JavaScript

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.

Question 1
Interview Beginner
Question

What are == and === in JavaScript?

Answer:

=== 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.

Question 2
Interview Intermediate
Question

Why is NaN === NaN false?

Answer:

IEEE. Use Number.isNaN or Object.is. isNaN('hello') coerces. Object.is also distinguishes +0 and -0. I would not === objects expecting deep equal.

Question 3
Interview Intermediate
Question

Compare two objects for equal contents?

Answer:

=== 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.

Question 4
Interview Beginner
Question

null == undefined?

Answer:

true for ==, false for ===. I use == null on purpose for missing. === everywhere else. I would not == 0 or == ''.

Question 5
Interview Advanced
Question

[] == false — why a trap?

Answer:

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