Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Object
  6. is()

Object.is()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2015⁩.

TheObject.is() static method determines whether two values arethe same value.

Try it

console.log(Object.is("1", 1));// Expected output: falseconsole.log(Object.is(NaN, NaN));// Expected output: trueconsole.log(Object.is(-0, 0));// Expected output: falseconst obj = {};console.log(Object.is(obj, {}));// Expected output: false

Syntax

js
Object.is(value1, value2)

Parameters

value1

The first value to compare.

value2

The second value to compare.

Return value

A boolean indicating whether or not the two arguments are the same value.

Description

Object.is() determines whether two values arethe same value. Two values are the same if one of the following holds:

  • bothundefined
  • bothnull
  • bothtrue or bothfalse
  • both strings of the same length with the same characters in the same order
  • both the same object (meaning both values reference the same object in memory)
  • bothBigInts with the same numeric value
  • bothsymbols that reference the same symbol value
  • both numbers and
    • both+0
    • both-0
    • bothNaN
    • or both non-zero, notNaN, and have the same value

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 beingtrue), butObject.is() doesn't coerce either value.

Object.is() is alsonot equivalent to the=== operator. The only difference betweenObject.is() and=== is in their treatment of signed zeros andNaN values. The=== operator (and the== operator) treats the number values-0 and+0 as equal, but treatsNaN as not equal to each other.

Examples

Using Object.is()

js
// Case 1: Evaluation result is the same as using ===Object.is(25, 25); // trueObject.is("foo", "foo"); // trueObject.is("foo", "bar"); // falseObject.is(null, null); // trueObject.is(undefined, undefined); // trueObject.is(window, window); // trueObject.is([], []); // falseconst foo = { a: 1 };const bar = { a: 1 };const sameFoo = foo;Object.is(foo, foo); // trueObject.is(foo, bar); // falseObject.is(foo, sameFoo); // true// Case 2: Signed zeroObject.is(0, -0); // falseObject.is(+0, -0); // falseObject.is(-0, -0); // true// Case 3: NaNObject.is(NaN, 0 / 0); // trueObject.is(NaN, Number.NaN); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-object.is

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp