Question presented to candidate: "What is the actual difference between Object.is(a, b), a == b, and a === b? Walk me through where all three agree, and the specific cases where they disagree."
What a strong answer should cover:
- == performs type coercion before comparing; === and Object.is never coerce types, so 1 === "1" and Object.is(1, "1") are both false while 1 == "1" is true.
- === and Object.is agree on almost everything, EXCEPT exactly two IEEE-754 floating point edge cases: NaN and negative zero.
- NaN === NaN is false (the famous exception), but Object.is(NaN, NaN) is true -- Object.is exists partly to give a correct way to test NaN equality without that gotcha.
- 0 === -0 is true, but Object.is(0, -0) is false -- Object.is is actually STRICTER than === in this one specific case, not simply a safer alias for it.
- None of the three perform structural/deep equality on objects or arrays -- two separately created array literals with identical contents are never equal under any of the three, since object comparison is always by reference.
Clarifying questions expected:
- "Should I also cover Array.prototype.includes, since it uses a related but different algorithm called SameValueZero?"
Code / implementation expected: Yes -- a runnable truth table covering NaN, -0, type coercion, and reference equality.