Skip to content
KodeTrail

Camp 2 · Step 7 of 18

Booleans, comparisons, and ===

True, false, and why professional JavaScript always compares with three equals signs.

12 min+50 XP

Booleans — true and false (lowercase in JavaScript!) — are the values every decision is made of.

Comparisons

JavaScript
OperatorMeaning
===equal (strict)
!==not equal (strict)
> < >= <=the usual suspects

Why === and not ==?

JavaScript also has a loose == that converts types before comparing — with famously surprising results:

JavaScript

5 == "5" is true?! Loose equality quietly converts the string, which sounds convenient and is actually a bug factory. The professional rule is simple: always use === and !==. Then a number never accidentally equals a string, and comparisons mean exactly what they say.

Logic: && || !

JavaScript

Combined with comparisons, this expresses real rules:

const canRideAlone = age >= 14 && hasHelmet;
Checkpoint

What does 7 === "7" evaluate to?

Checkpoint

If a = true, b = false: what is (a || b) && !b?