Everyone knows the one-line answer: == compares with coercion, === doesn't. That's the answer that gets you a follow-up question, not a passed interview. So let's actually go one level deeper.
The Answer Nobody Stops At
1 == "1"; // true
1 === "1"; // false
0 == false; // true
0 === false; // false
null == undefined; // true
null === undefined; // false
Fine so far. But then someone asks the real question:
"Why is [] == false true?"
And that's where most people just guess.
What Coercion Actually Does
Here's the rule, and it's shorter than people expect: when you use ==, JavaScript picks one side and converts it to match the other's type, following a specific, fixed order, not a coin flip.
- If one side is a boolean, it gets converted to a number first (true → 1, false → 0)
- If one side is a number and the other a string, the string gets converted to a number
- If one side is an object and the other isn't, the object gets converted to a primitive (via toString()/valueOf())
So [] == false walks through it like this: false becomes 0. Now it's [] == 0. [] is an object, so it converts to a primitive. An empty array's toString() is "". Now it's "" == 0. "" converts to 0. 0 == 0 → true.
[] == false;
// false -> 0
// [] -> "" (via toString)
// "" -> 0
// 0 == 0 -> true
Nobody memorizes that chain. What you actually want is the mental model, one side gets walked toward the other's type, step by step, until they're comparable.

The Follow-Up That Actually Matters
If they push further, they'll ask why === exists at all instead of just always using == carefully. Honest answer: because the coercion table above is exactly the kind of thing that's easy to get right in an interview and wrong at 2am debugging a real form validation bug. === just removes the whole category of mistake.
Quick Recap
- == triggers type coercion; === doesn't; that part everyone knows
- Coercion isn't random, booleans go to numbers, objects go to primitives, then numbers/strings get compared
- [] == false is true because of a chain of conversions, not one weird JS quirk
- In real code, reach for === by default; save == for the rare case you actually want coercion, and say so out loud when you use it
And that last point is honestly the best answer to give if an interviewer asks which one you'd actually use day to day.




Comments
No comments yet — be the first to share your thoughts.