Interview Q&A / JavaScript

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How is Object.is different from the === operator?

SHORT ANSWER

Object.is works like === with two differences: Object.is(NaN, NaN) is true, and Object.is(0, -0) is false. React uses it to compare state values.

Explain it simply

=== is the strict equality check most code uses. It has two odd corners:

  • NaN === NaN is false, even though both sides are the same thing.
  • 0 === -0 is true, even though JavaScript does keep a separate negative zero.

Object.is (ES6) fixes both corners. It is called "SameValue" equality. For everything else it behaves exactly like ===: no type conversion, and objects are compared by reference.

Negative zero is rare but real. For example, -5 * 0 produces -0, and 1 / -0 is -Infinity, so the sign can change later results.

Example

js
console.log(NaN === NaN);            // Output: false
console.log(Object.is(NaN, NaN));    // Output: true

console.log(0 === -0);               // Output: true
console.log(Object.is(0, -0));       // Output: false

console.log(Object.is("5", 5));      // Output: false
console.log(Object.is({}, {}));      // Output: false

const a = { id: 1 };
const b = a;
console.log(Object.is(a, b));        // Output: true

What to say in the interview

"Object.is implements SameValue equality. It matches === except that NaN equals NaN and +0 doesn't equal -0. There's no coercion and objects are still compared by reference. React's useState and useEffect dependency checks use Object.is, which is why setting the same object reference doesn't trigger a re-render, while setting a new object with the same contents does."

Common mistakes

  • Thinking Object.is does a deep comparison of objects. It does not.
  • Using it everywhere instead of ===; it is only needed when NaN or -0 matter.

#javascript#equality#types

Related questions

Practise more JavaScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open JavaScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.