Object.is vs Triple Equals in JavaScript

In JavaScript, both Object.is() and the strict equality operator (===) compare two values to check if they are the same without performing type conversion. However, they differ in how they handle two specific edge cases: NaN (Not-a-Number) and signed zeroes (+0 and -0). While === adheres closely to IEEE 754 standard arithmetic rules, Object.is() implements the “SameValue” algorithm to determine whether two values are fundamentally identical in memory and representation.

Key Differences

The differences between Object.is() and === come down entirely to two special numerical scenarios.

1. Handling NaN

Under the IEEE 754 standard used by the strict equality operator, NaN is not equal to any value, including itself. In contrast, Object.is() considers NaN to be equal to another NaN.

// Strict equality (===)
console.log(NaN === NaN); // false

// Object.is()
console.log(Object.is(NaN, NaN)); // true

2. Handling Signed Zeroes (+0 vs -0)

The strict equality operator treats positive zero and negative zero as completely identical. Object.is() differentiates between the two.

// Strict equality (===)
console.log(+0 === -0); // true

// Object.is()
console.log(Object.is(+0, -0)); // false
console.log(Object.is(+0, 0));  // true
console.log(Object.is(-0, -0)); // true

Similarities

For all other comparisons, Object.is() and === behave identically:

const a = { name: "Alice" };
const b = { name: "Alice" };
const c = a;

// Distinct references
console.log(a === b);            // false
console.log(Object.is(a, b));    // false

// Same reference
console.log(a === c);            // true
console.log(Object.is(a, c));    // true

Summary Table

Expression === Result Object.is() Result
NaN === NaN false true
+0 === -0 true false
'text' === 'text' true true
false === false true true
{} === {} false false

When to Use Each