Object.is()
Object.is(value1, value2) Returns:
boolean · Updated March 16, 2026 · Object Methods object comparison equality
Object.is() compares two values for strict equality with subtle differences from the === operator. Unlike ===, it treats NaN as equal to itself and distinguishes between positive and negative zeros. This method is particularly useful when you need exact equality semantics, such as in polyfills or when working with values that have special zero representations.
Syntax
Object.is(value1, value2)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| value1 | any | — | First value to compare |
| value2 | any | — | Second value to compare |
Examples
Basic usage
Object.is(1, 1);
// true
Object.is(1, '1');
// false (different types)
Object.is(NaN, NaN);
// true (=== returns false)
Zero handling
Object.is(0, -0);
// false (=== returns true)
Object.is(-0, -0);
// true
Object.is(+0, +0);
// true
Object.is(0, 0);
// true
Object identity
const obj = {};
Object.is(obj, obj);
// true (same reference)
Object.is({}, {});
// false (different objects)
const arr = [Global_Objects::eval];
Object.is(arr, arr);
// true
Common Patterns
Use Object.is() when you need precise equality checking, especially when dealing with NaN comparisons or when the distinction between positive and negative zero matters:
// Safe NaN check (Number.isNaN also works, but Object.is works too)
function isNaN(value) {
return Object.is(value, NaN);
}
// Checking for signed zero in physics calculations
function hasNegativeZero(n) {
return Object.is(n, -0);
}
// Custom equality for libraries that need === semantics but with NaN handling
function deepEqual(a, b) {
if (a === b) return true;
if (Object.is(a, b)) return true;
// ... more complex comparison
}
See Also
- Object.seal() — Seal object
- Object.keys() — Get array of object keys