JavaScript Object.is() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

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.

JavaScript
Object.is(value1, value2)
CallWhat 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
JavaScript
Object.is(value1, value2)
JavaScript
is(value1: any, value2: any): boolean;

Parameters

ParameterDescription
value1Required. The first value to compare.
value2Required. The second value to compare.

Return Value

Return ValueDescription
booleantrue if the values are SameValue-equal; otherwise false.

JavaScript Examples

Example 1 — Basic Use

Compare ordinary values — results match ===.

JavaScript
console.log(Object.is(25, 25));
console.log(Object.is("hi", "hi"));
console.log(Object.is(true, 1));
console.log(Object.is(null, null));
Try It Yourself

How It Works

  1. Same primitives Equal numbers and strings return true, just like ===.
  2. No coercion true and 1 are different types, so the result is false.
  3. null matches null Object.is(null, null) is true.

Example 2 — NaN vs ===

Object.is treats NaN as equal to itself.

JavaScript
console.log(NaN === NaN);
console.log(Object.is(NaN, NaN));
console.log(Number.isNaN(NaN));
Try It Yourself

How It Works

  1. === fails for NaN In JavaScript, NaN === NaN is always false.
  2. Object.is agrees Object.is(NaN, NaN) returns true — both sides are the same value.
  3. 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.

JavaScript
console.log(+0 === -0);
console.log(Object.is(+0, -0));
console.log(Object.is(+0, 0));
console.log(Object.is(-0, -0));
Try It Yourself

How It Works

  1. === sees one zero +0 === -0 is true in JavaScript.
  2. Object.is separates them Object.is(+0, -0) is false because the signs differ.
  3. Same sign matches +0 matches 0, and -0 matches -0.

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 support
Object.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.

Next: isExtensible()

Ask whether an object can still receive new properties.

isExtensible() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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