CoursePart 1 — JavaScript for PlaywrightLesson 1.6
Lesson 1.6Part 1 — JavaScript for Playwright

Comparison operators

=== and !== — asking JavaScript a yes/no question.

Lesson 1.6of 24
Next

Step 1

The idea

01

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

02
Output
true
false
true
true
false
true
comparisons.js
const 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?
Terminal
$ node comparisons.js
⚠️Warning
Always use === (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

03

Predict the output before running:

js
console.log(10 == "10");    // == double equals
console.log(10 === "10");   // === triple equals

Write 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

04

Comparisons are the foundation of any pass/fail logic. Here's a simple grading system built entirely with comparison operators:

grading.js
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}`);
}
Terminal
$ node grading.js
Output
Score: 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: true

Every pass/fail decision in any program — grading systems, access control, form validation — uses these exact same operators.

Recap

3 key points
  • 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.