Skip to content
JavaScript·Intermediate·Coding·1 min read

How does Object.is differ from ===?

Short interview answer

It behaves identically to === for almost every value, but differs in exactly two cases: Object.is(NaN, NaN) is true where NaN === NaN is false, and Object.is(0, -0) is false where 0 === -0 is true.

Example

JavaScript
Object.is(NaN, NaN); // true   (=== gives false)Object.is(0, -0);    // false  (=== gives true)Object.is(1, 1);     // true   (same as ===)

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Equality and type coercion

Related questions