Boolean Logic

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

This Boolean Logic worksheet is part of the JavaScript Coding without HTML and CSS journey. Print it as a booklet?

Boolean Logic

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does && return true only if both sides are true?
A No
B Yes
2. Does || return true if either side is true?
A Yes
B No
3. Is 'and' a valid JavaScript operator for combining conditions?
A No
B Yes
4. Does ! reverse a boolean value?
A Yes
B No
5. Is a single & the same as && in JavaScript?
A Yes
B No

Match the Pairs

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

Left columnRight column
1isSunny && isWarm AWrong - use || instead of the word 'or'
2isSunny || isWarm BWrong - use && instead of the word 'and'
3Reverses a boolean's value ChasTicket && hasID
4Combines two conditions, requiring both to be true D!isOpen
5console.log(a and b); ETrue only if both isSunny and isWarm are true
6console.log(x or y); FTrue if at least one of isSunny or isWarm is true

Definitions

&&

Fill in the Blanks

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

1.
console.log(isSunny __ isWarm);
2.
console.log(isSunny __ isWarm);
3.
console.log(_isSunny);
4.
let ready = hasTicket __ hasID;
5.
let closed = _isOpen;

Spot the Error

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

Question 1
A console.log(a and b);
B let a = true;
C let b = false;
Question 2
A let x = true;
B let y = false;
C console.log(x or y);
Question 3
A let flag = true;
B console.log(not flag);
C console.log(!flag);
Question 4
A let p = true;
B let q = false;
C console.log(p & q);
Question 5
A console.log(m | n);
B let m = true;
C let n = false;

Answer Key

Boolean Logic
Section A: Quick Questions
Q1
B — Yes
Q2
A — Yes
Q3
A — No
Q4
A — Yes
Q5
B — No
Section B: Match the Pairs
Q1
isSunny && isWarm → True only if both isSunny and isWarm are true
Q2
isSunny || isWarm → True if at least one of isSunny or isWarm is true
Q3
Reverses a boolean's value → !isOpen
Q4
Combines two conditions, requiring both to be true → hasTicket && hasID
Q5
console.log(a and b); → Wrong - use && instead of the word 'and'
Q6
console.log(x or y); → Wrong - use || instead of the word 'or'
Section C: Definitions
Q1
&& — A logical operator that returns true only if both conditions on either side are true.
Section D: Fill in the Blanks
Q1
console.log(isSunny && isWarm);
Q2
console.log(isSunny || isWarm);
Q3
console.log(!isSunny);
Q4
let ready = hasTicket && hasID;
Q5
let closed = !isOpen;
Section E: Spot the Error
Q1
A — Use &&, not the word 'and', to combine conditions.
Q2
C — Use ||, not the word 'or', to combine conditions.
Q3
B — Use !, not the word 'not', to reverse a boolean.
Q4
C — Use &&, not a single &, for logical AND.
Q5
A — Use ||, not a single |, for logical OR.