The boolean data type: true and false

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

The boolean data type: true and false

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line stores a boolean value?
A let isRaining = true;
B let isRaining = "true";
2. Which is a valid boolean value in JavaScript?
A false
B False
3. What is the data type of true?
A string
B boolean
4. What does this log? console.log(typeof "false");
A boolean
B string
5. What value does 5 > 3 give?
A true
B "true"

Match the Pairs

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

Left columnRight column
1let isRaining = true; Alet gameOver = false;
2let isAdult = age >= 18; BStores the boolean result of a comparison
3A boolean is written in lowercase with no quotes Cconsole.log(typeof "true");
4true and "true" are different: one is a boolean, the other is a string DBooleans must be lowercase. True with a capital T is not a boolean, so JavaScript gives a ReferenceError. Write true.
5let isOpen = True; EThe quotes turn false into a string, not a boolean. Remove the quotes and write false.
6let isFinished = "false"; FStores a yes/no value in a variable as a boolean

Definitions

boolean

Fill in the Blanks

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

1.
let isRaining = ____;
2.
console.log(typeof false); // _______
3.
let age = 20; let canVote = age __ 18;
4.
console.log(true ___ "true"); // false
5.
let score = 72; let isPassing = score > 50; console.log(_________);

Spot the Error

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

Question 1
A let score = 10;
B let passed = score >= 5;
C let isReady = True;
D console.log(isReady);
Question 2
A let isHappy = "true";
B console.log(isHappy);
C console.log(typeof isHappy);
Question 3
A let age = 14;
B let canVote = "age >= 18";
C console.log(canVote);
Question 4
A let isOn = true;
B let count = 0;
C let isDone = fasle;
D console.log(isDone);
Question 5
A let temp = 30;
B let isHot = temp > 25;
C console.log("isHot");
D console.log(typeof isHot);

Answer Key

The boolean data type: true and false
Section A: Quick Questions
Q1
A — let isRaining = true;
Q2
A — false
Q3
B — boolean
Q4
B — string
Q5
A — true
Section B: Match the Pairs
Q1
let isRaining = true; → Stores a yes/no value in a variable as a boolean
Q2
let isAdult = age >= 18; → Stores the boolean result of a comparison
Q3
A boolean is written in lowercase with no quotes → let gameOver = false;
Q4
true and "true" are different: one is a boolean, the other is a string → console.log(typeof "true");
Q5
let isOpen = True; → Booleans must be lowercase. True with a capital T is not a boolean, so JavaScript gives a ReferenceError. Write true.
Q6
let isFinished = "false"; → The quotes turn false into a string, not a boolean. Remove the quotes and write false.
Section C: Definitions
Q1
boolean — A data type with only two values, true or false, written in lowercase with no quotes. Comparisons like 5 > 3 give a boolean, and true is not the same as the string "true".
Section D: Fill in the Blanks
Q1
let isRaining = true;
Q2
console.log(typeof false); // boolean
Q3
let age = 20; let canVote = age >= 18;
Q4
console.log(true === "true"); // false
Q5
let score = 72; let isPassing = score > 50; console.log(isPassing);
Section E: Spot the Error
Q1
C — Boolean values must be lowercase. True with a capital T is not defined and causes a ReferenceError. It should be let isReady = true;
Q2
A — Quotes turn true into a string, so typeof would print string instead of boolean. A boolean is written without quotes: let isHappy = true;
Q3
B — Inside quotes the comparison is just text, so it is never worked out. Without the quotes, age >= 18 gives the boolean false.
Q4
C — false is spelled wrong. JavaScript sees fasle as a variable name that does not exist and gives a ReferenceError. It should be false.
Q5
C — Quotes make console.log print the words isHot instead of the boolean stored in the variable. It should be console.log(isHot); which prints true.