Equality: == vs === in JavaScript
Strict equality (===) compares type and value with no conversion: 1 === "1" is false, and it is the correct default everywhere. Loose equality (==) coerces first through rules nobody fully memorizes — null == undefined is true (the sanctioned exception), "" == false is true, [] == false is true — producing bugs that read as correct code.
Object.is() refines further: Object.is(NaN, NaN) is true (unlike ===) and Object.is(-0, +0) is false (unlike ===). Team rule: === always, == never (except == null as the deliberate covers-both check), Object.is for NaN/zero edge cases.
=== compares type + value
1 === "1" is false, 1 === 1 true, {} === {} false (different references) — predictable, no coercion.
== coerces unpredictably
"" == false, 0 == false, [] == false are all true — implicit conversions that read as equality but aren't.
The null exception
x == null covers null AND undefined in one check — the single legitimate ==, recognized by every linter.
Object.is for edges
SameValue semantics: NaN equals NaN, -0 differs from +0 — reach for it in numeric edge-case code.
console.log(1 == "1", 1 === "1");console.log(null == undefined, null === undefined);console.log(NaN === NaN, Object.is(NaN, NaN));Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.