Equality Interview Questions
== vs ===, type coercion, and Object.is — with a spoken sample answer.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What are == and === in JavaScript?
=== is strict equality. No type coercion. 0 === '0' is false. NaN === NaN is also false, which surprises people. == coerces types. '' == 0 is true. null == undefined is true, but null === undefined is false. I use === and !== unless I intentionally want null and undefined to match. Object.is is the one that treats NaN as equal to NaN and distinguishes +0 and -0. In an interview I would say I treat == as a trap unless the codebase already depends on it.
Why is NaN === NaN false?
IEEE. Use Number.isNaN or Object.is. isNaN('hello') coerces. Object.is also distinguishes +0 and -0. I would not === objects expecting deep equal.
Compare two objects for equal contents?
=== is identity. For contents, a deep-equal helper, or JSON.stringify with its quirks. In interviews I write shallow equal and mention deep as a follow-up. Date and Map need special cases.
null == undefined?
true for ==, false for ===. I use == null on purpose for missing. === everywhere else. I would not == 0 or == ''.
[] == false — why a trap?
Coercion. I would never write it. Boolean(array.length). I can walk the spec if they insist. I refuse the style in product code.
Practice with AI mock interviews
Run JavaScript mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required