JavaScript Object.is() Method
The Object.is() static method checks whether two values are the same, like === but treating NaN as equal to itself and +0 and -0 as different.
Description
The Object.is() static method determines whether two values are the same value. It behaves like === with two exceptions: Object.is(NaN, NaN) is true, and Object.is(0, -0) is false. Objects are still compared by reference. It's mainly useful in libraries that need exact comparisons, such as change detection.
Its comparison is called the SameValue algorithm. Arrays and Map keys use a slightly different version, SameValueZero, which treats NaN as equal to itself but +0 and -0 as the same, which is why includes() can find NaN.
Frameworks such as React use Object.is() to decide whether a value has changed, so state updates that set the same object, even with different contents, don't trigger a re-render. That's why updates are usually made by creating new objects rather than mutating existing ones.
Syntax
Object.is(value1, value2)Parameters
- value1The first value.
- value2The second value.
Return Value
true if the two values are the same value, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Object.is() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





