The Object.is()
static method determines whether two values are the same value.
The Object.is()
static method determines whether two values are the same value.
Object.is(value1, value2)
A boolean indicating whether or not the two arguments are the same value.
Object.is()
determines whether two values are the same value. Two values are the same if one of the following holds:
undefined
null
true
or both false
Object.is()
is not equivalent to the ==
operator. The ==
operator applies various coercions to both sides (if they are not the same type) before testing for equality (resulting in such behavior as "" == false
being true
), but Object.is()
doesn't coerce either value.
Object.is()
is also not equivalent to the ===
operator. The only difference between Object.is()
and ===
is in their treatment of signed zeros and NaN
values. The ===
operator (and the ==
operator) treats the number values -0
and +0
as equal, but treats NaN
as not equal to each other.
// Case 1: Evaluation result is the same as using === Object.is(25, 25); // true Object.is("foo", "foo"); // true Object.is("foo", "bar"); // false Object.is(null, null); // true Object.is(undefined, undefined); // true Object.is(window, window); // true Object.is([], []); // false const foo = { a: 1 }; const bar = { a: 1 }; const sameFoo = foo; Object.is(foo, foo); // true Object.is(foo, bar); // false Object.is(foo, sameFoo); // true // Case 2: Signed zero Object.is(0, -0); // false Object.is(+0, -0); // false Object.is(-0, -0); // true // Case 3: NaN Object.is(NaN, 0 / 0); // true Object.is(NaN, Number.NaN); // true
Specification |
---|
ECMAScript Language Specification # sec-object.is |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
is |
19 | 12 | 22 | 15 | 9 | 25 | 22 | 14 | 9 | 1.5 | 4.4 | 1.0 | 0.10.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is