JavaScript Object.is() Method

Definition
Object.is(a, b) tells you whether two values are the same using the SameValue algorithm. For most values it matches ===.
Two important differences: Object.is(NaN, NaN) is true (unlike ===), and Object.is(+0, -0) is false (also unlike ===).
Syntax
Call Object.is() like this. Start with this line.
Object.is(value1, value2)
| Call | What it does |
|---|
Object.is(value1, value2) | Returns true when both values are the same under SameValue rules. |
Built into JavaScript. Call on Object — no import required.
Library declarations
Object.is(value1, value2)
is(value1: any, value2: any): boolean;
Parameters
| Parameter | Description |
|---|
| value1 | Required. The first value to compare. |
| value2 | Required. The second value to compare. |
Return Value
| Return Value | Description |
|---|
| boolean | true if the values are SameValue-equal; otherwise false. |
JavaScript Examples
Example 1 — Basic Use
Compare ordinary values — results match ===.
console.log(Object.is(25, 25));
console.log(Object.is("hi", "hi"));
console.log(Object.is(true, 1));
console.log(Object.is(null, null));
How It Works
- Same primitives Equal numbers and strings return
true, just like ===. - No coercion
true and 1 are different types, so the result is false. - null matches null
Object.is(null, null) is true.
Example 2 — NaN vs ===
Object.is treats NaN as equal to itself.
console.log(NaN === NaN);
console.log(Object.is(NaN, NaN));
console.log(Number.isNaN(NaN));
How It Works
- === fails for NaN In JavaScript,
NaN === NaN is always false. - Object.is agrees
Object.is(NaN, NaN) returns true — both sides are the same value. - Detecting NaN To test one value,
Number.isNaN(x) is still the clearest choice.
Example 3 — +0 and -0
Object.is distinguishes positive zero from negative zero.
console.log(+0 === -0);
console.log(Object.is(+0, -0));
console.log(Object.is(+0, 0));
console.log(Object.is(-0, -0));
How It Works
- === sees one zero
+0 === -0 is true in JavaScript. - Object.is separates them
Object.is(+0, -0) is false because the signs differ. - Same sign matches
+0 matches 0, and -0 matches -0.
Compatibility
Browser & Runtime Support
Object.is() has been available since ES6 (ES2015). It is Baseline and widely supported.
✓ Baseline · ES6
Object.is()
Supported in Chrome 30+, Firefox 22+, Safari 9+, Edge 12+, and Node.js 0.12+.
98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportObject.is Excellent
Bottom line: Safe everywhere modern. Reach for it when NaN or signed-zero equality matters; otherwise === is fine.
Frequently Asked Questions
It compares two values with the SameValue algorithm. For most values it matches ===, with special rules for NaN and +0/-0.
Object.is(NaN, NaN) is true, while NaN === NaN is false. Object.is(+0, -0) is false, while +0 === -0 is true.
Usually no. === is clearer for everyday code. Use Object.is when you specifically care about NaN equality or distinguishing +0 from -0.
No. Two different object references are not the same, even if they have identical properties.
No. Object.is compares two values. Object.isExtensible checks whether new properties can be added to an object.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful