Comparison operators
=== and !== — asking JavaScript a yes/no question.
Step 1
The idea
A comparison operator asks a question and always gets one of two answers: true or false.
Think of it like a referee at a game — they look at two things and make a call: "equal or not?", "bigger or smaller?"
There are six comparison operators in JavaScript, and you'll use them constantly in if statements and Playwright assertions.
Step 2
See it run
true
false
true
true
false
trueconst score = 80;
const passing = 75;
console.log(score > passing); // true — is 80 greater than 75?
console.log(score < passing); // false — is 80 less than 75?
console.log(score >= 80); // true — is 80 greater than OR equal to 80?
console.log(score !== 50); // true — is 80 NOT equal to 50?
console.log(score === 100); // false — is 80 strictly equal to 100?
console.log(score === 80); // true — is 80 strictly equal to 80?$ node comparisons.js=== (triple equals), never == (double equals). Triple equals checks both value AND type. Double equals does type coercion and produces surprising results.Step 3
Now you try
Predict the output before running:
console.log(10 == "10"); // == double equals
console.log(10 === "10"); // === triple equalsWrite your guess, then run it. The results will surprise you — and explain exactly why we always use triple equals.
Step 4
Why a tester cares
Comparisons are the foundation of any pass/fail logic. Here's a simple grading system built entirely with comparison operators:
function getGrade(score) {
if (score >= 90) return "A";
if (score >= 80) return "B";
if (score >= 70) return "C";
if (score >= 60) return "D";
return "F";
}
const scores = [95, 83, 71, 58, 100];
for (const score of scores) {
const passed = score >= 60;
const grade = getGrade(score);
console.log(`Score: ${score} | Grade: ${grade} | Passed: ${passed}`);
}$ node grading.jsScore: 95 | Grade: A | Passed: true
Score: 83 | Grade: B | Passed: true
Score: 71 | Grade: C | Passed: true
Score: 58 | Grade: F | Passed: false
Score: 100 | Grade: A | Passed: trueEvery pass/fail decision in any program — grading systems, access control, form validation — uses these exact same operators.
Recap
- 1=== means strictly equal (same value AND same type) — always use this.
- 2!== means not equal. > < >= <= work as you'd expect from maths.
- 3Comparison operators return true or false — they're the engine behind if statements and test assertions.