Comparison operators: !==, <, >, <= and >=

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

Comparison operators: !==, <, >, <= and >=

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does 50 >= 50 give?
A false
B true
2. What does 50 > 50 give?
A false
B true
3. Which expression checks that score is NOT equal to 10?
A score !== 10
B score =! 10
4. let age = 12; What does age < 13 give?
A false
B true
5. A ride needs a height of at least 140. Which test is correct for the height variable?
A height >= 140
B height > 140

Match the Pairs

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

Left columnRight column
1score !== 0 AChecks that score is not equal to 0, giving true when score is any other value
2age >= 13 Bpoints <= 100
3The boundary value is not included when you use > on its own, so 50 > 50 is false Cconsole.log(50 > 50);
4Comparing a variable with a number to check it is at most 100 D=> is not a comparison operator. Greater than or equal to must be written >= with the > first.
5if (lives =! 0) { ETrue when age is 13 or more, so 13 itself counts
6if (mark => 50) { FThe symbols are in the wrong order and use only one equals sign. Not equal is written !==, and =! is not a comparison.

Definitions

!== < > <= >=

Fill in the Blanks

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

1.
console.log(50 __ 50);
2.
console.log(50 _ 50);
3.
let score = 42; console.log(score ___ 50);
4.
let age = 13; console.log(age _ 18);
5.
let lives = 3; console.log(lives __ 3);

Spot the Error

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

Question 1
A let score = 50;
B // 50 or more passes
C let pass = score > 50;
D console.log(pass);
Question 2
A let lives = 3;
B let alive = lives =! 0;
C console.log(alive);
Question 3
A let temp = 35;
B if (temp => 30) {
C console.log("Hot");
D }
Question 4
A let diff = 7 <> 8;
B console.log(diff);
C console.log(7 < 5);
Question 5
A let age = 16;
B let msg = "Too young";
C if (age = 16) {
D msg = "Can drive";
E }

Answer Key

Comparison operators: !==, <, >, <= and >=
Section A: Quick Questions
Q1
B — true
Q2
A — false
Q3
A — score !== 10
Q4
B — true
Q5
A — height >= 140
Section B: Match the Pairs
Q1
score !== 0 → Checks that score is not equal to 0, giving true when score is any other value
Q2
age >= 13 → True when age is 13 or more, so 13 itself counts
Q3
The boundary value is not included when you use > on its own, so 50 > 50 is false → console.log(50 > 50);
Q4
Comparing a variable with a number to check it is at most 100 → points <= 100
Q5
if (lives =! 0) { → The symbols are in the wrong order and use only one equals sign. Not equal is written !==, and =! is not a comparison.
Q6
if (mark => 50) { → => is not a comparison operator. Greater than or equal to must be written >= with the > first.
Section C: Definitions
Q1
!== < > <= >= — Comparison operators: !== checks two values are not equal, while <, >, <= and >= compare size. Each gives true or false. 50 >= 50 is true, but 50 > 50 is false.
Section D: Fill in the Blanks
Q1
console.log(50 >= 50);
Q2
console.log(50 > 50);
Q3
let score = 42; console.log(score !== 50);
Q4
let age = 13; console.log(age < 18);
Q5
let lives = 3; console.log(lives <= 3);
Section E: Spot the Error
Q1
C — The comment says 50 or more passes, but score > 50 is false when score is exactly 50. It should be score >= 50.
Q2
B — The not equal operator is written !== with the ! first. =! is not a valid comparison operator. It should be lives !== 0.
Q3
B — => is not a comparison operator. 'Greater than or equal to' is written >= with the > first. It should be temp >= 30.
Q4
A — JavaScript has no <> operator. Not equal is written !==. It should be 7 !== 8.
Q5
C — A single = assigns a value, it does not compare. To check whether age is 16 or more, use >=. It should be age >= 16.