Lesson 12 of 80
== converts types before comparing; === refuses to. Knowing the handful of coercion rules turns 'JS is weird' into 'JS is predictable, if you know the rule.'
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
What does `null == undefined` evaluate to, and why?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
=== compares value and type — no conversion, ever. == first tries to make both sides the same type, then compares. The famous "weirdness" ([] == false, "" == 0) isn't random — it's a small, fixed set of coercion rules being followed exactly.
"" == 0 // true — "" coerces to 0
[] == false // true — [] -> "" -> 0, false -> 0
null == undefined // true — special-cased, equal only to each other
null === undefined // false — different types, no coercion
0 === -0 // true
NaN === NaN // false — NaN is never equal to anything, including itself
When == compares a primitive to an object (like [] == false), the object is converted to a primitive first (via toString/valueOf), then the usual numeric coercion rules apply to both sides. null and undefined are the one hard-coded exception: they're == to each other and to nothing else — not even 0 or "".
[] == false — different types. == tries to coerce them to a common type before comparing.
== isn't "wrong," it's a specific algorithm. The Abstract Equality Comparison in the spec is a real, fixed table of rules — the reputation for chaos comes from not knowing the table, not from actual randomness.=== everywhere, with == null as the one common intentional exception (it catches both null and undefined in one check).0 == "" is true, but 0 == "0" is also true while "" == "0" is false — coercion is pairwise, not transitive."What's the difference between == and ===, and can you name three surprising == results?" checks whether you actually understand coercion rules or just parrot "always use triple equals" without knowing why.