The number data type

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

The number data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which one is a number in JavaScript?
A let age = "13";
B let age = 13;
2. Which value is a decimal number?
A 3.5
B "3.5"
3. Which one is a negative number?
A let temp = -2;
B let temp = "-2";
4. What does 5 + 5 give?
A 10
B 55
5. Which statement is true?
A 5 and "5" are both numbers
B 5 is a number and "5" is a string

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1let score = 3.5; Alet total = 7 + 3;
2let temp = -2; BStores a negative number. The minus sign is part of the number, and it still has no quotes.
3A whole number with no quotes is a number, so you can calculate with it CThe quotes make "13" a string, so age + 2 joins the text and prints 132 instead of adding to give 15. Remove the quotes: let age = 13;
4A value in quotes is a string, not a number, even if it looks like a number DA decimal number uses a full stop, not a comma. Write let price = 3.50; so it is one number.
5let age = "13"; console.log(age + 2); EStores a decimal number. It has no quotes, so JavaScript treats it as a number you can calculate with.
6let price = 3,50; Flet answer = "5";

Definitions

number

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let lives = 3; console.log(lives _ 2);
2.
// negative number: minus two let change = __;
3.
// decimal number: three and a half let price = ___;
4.
let a = 5; let b = "5"; console.log(typeof _); // number
5.
let n = 7; console.log(typeof n); // ______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let price = 3.5;
B let qty = 4;
C let total = price x qty;
D console.log(total);
Question 2
A let score = 7;
B let bonus = 3;
C let total = score + bonus;
D console.log(type of total);
Question 3
A let a = 1.5;
B let b = 2.5;
C let c = 3,5;
D console.log(a + b + c);
Question 4
A let n = "5";
B let total = n + 2;
C console.log(total);
Question 5
A let big = 1,000;
B let half = big / 2;
C console.log(half);

Answer Key

The number data type
Section A: Quick Questions
Q1
B — let age = 13;
Q2
A — 3.5
Q3
A — let temp = -2;
Q4
A — 10
Q5
B — 5 is a number and "5" is a string
Section B: Match the Pairs
Q1
let score = 3.5; → Stores a decimal number. It has no quotes, so JavaScript treats it as a number you can calculate with.
Q2
let temp = -2; → Stores a negative number. The minus sign is part of the number, and it still has no quotes.
Q3
A whole number with no quotes is a number, so you can calculate with it → let total = 7 + 3;
Q4
A value in quotes is a string, not a number, even if it looks like a number → let answer = "5";
Q5
let age = "13"; console.log(age + 2); → The quotes make "13" a string, so age + 2 joins the text and prints 132 instead of adding to give 15. Remove the quotes: let age = 13;
Q6
let price = 3,50; → A decimal number uses a full stop, not a comma. Write let price = 3.50; so it is one number.
Section C: Definitions
Q1
number — A value written without quotes, whole (7), decimal (3.5) or negative (-2), that you can calculate with. 5 is a number but '5' in quotes is a string, which is text.
Section D: Fill in the Blanks
Q1
let lives = 3; console.log(lives + 2);
Q2
// negative number: minus two let change = -2;
Q3
// decimal number: three and a half let price = 3.5;
Q4
let a = 5; let b = "5"; console.log(typeof a); // number
Q5
let n = 7; console.log(typeof n); // number
Section E: Spot the Error
Q1
C — The letter x is not a multiplication operator in JavaScript. Numbers are multiplied with *, so the line should be let total = price * qty;
Q2
D — typeof is one word. Writing 'type of' with a space is a syntax error. It should be console.log(typeof total); which prints number.
Q3
C — Decimal numbers use a full stop (decimal point), not a comma. A comma here is a syntax error. It should be let c = 3.5;
Q4
A — Quotes make "5" a string, which is text. Then n + 2 joins the text and prints 52 instead of adding to make 7. It should be let n = 5;
Q5
A — Numbers are written without commas. The comma causes a syntax error. It should be let big = 1000;