== vs ===: what's the difference?
By FrontendPro Editorial Team Updated 9/26/2026
Answer
=== compares value and type with no conversion. == converts the operands to a common type first, then compares.
1 === "1"; // false — different types
1 == "1"; // true — "1" is converted to 1
null == undefined; // true
null === undefined; // false
0 == false; // true
"" == false; // true
[] == false; // true ← [] becomes "" becomes 0
That last group is why == has a bad reputation: the conversion rules are non-obvious and produce results almost nobody predicts.
A few results worth knowing
NaN === NaN; // false — NaN equals nothing, including itself
0 === -0; // true
"" == 0; // true
"0" == 0; // true
"" == "0"; // false ← not transitive
The last three together show == is not even transitive, which is enough reason to avoid it.
Use === by default
The one idiomatic exception is == null, which is true for both null and undefined and is a concise way to check "no value":
if (value == null) return; // catches null and undefined
if (value === null || value === undefined) return; // same thing, longer
For the awkward cases
Object.is is like === except it distinguishes +0 from -0 and treats NaN as equal to itself. Number.isNaN(x) is the usual way to test for NaN.
Objects compare by reference either way
{ a: 1 } === { a: 1 }; // false — two different objects
Neither operator looks at contents. For structural comparison you need a deep-equal helper, or compare a stable key such as an id.
