Object.is()

  • Revision slug: JavaScript/Reference/Global_Objects/Object/is
  • Revision title: is
  • Revision id: 372645
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment

Revision Content

{{harmony}}
{{fx_minversion_header("22")}}

Summary

Determine whether the passed two values are really same.

Method of Object
Implemented in JavaScript 1.8.5+
ECMAScript Edition ECMAScript 6th Edition

Syntax

Object.is(value1, value2)

Parameters

value1
First value to be compared
value2
Second value to be compared

Description

Object.is is quite simliar to the === operator. In contrast the function however checks if two values are indistingushiable instead of just equal. This difference is only oberservable for two values, NaN and -0.

Examples

Object.is("foo", "foo");     // true
Object.is(window, window);   // true

Object.is("foo", "bar");     // false
Object.is([], []);           // false

var test = {a: 1};
Object.is(test, test)       // true

Object.is(null, null)       // true

// Special Cases
Object.is(0, -0);            // false
Object.is(-0, -0);           // true
Object.is(NaN, 0/0);         // true

 

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}}

{{CompatGeckoDesktop("22")}}

{{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatGeckoDesktop("22")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

 

Revision Source

<div>
  {{harmony}}</div>
<div>
  {{fx_minversion_header("22")}}</div>
<h2 id="Summary">Summary</h2>
<p>Determine whether the passed two values are really same.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Method of<code> <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object" title="JavaScript/Reference/Global_Objects/Object">Object</a></code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.8.5+</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>ECMAScript 6th Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<code>Object.is(value1, value2)</code></pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
  <dt>
    <em><code>value1</code></em></dt>
  <dd>
    First value to be compared</dd>
  <dt>
    <em><code>value2</code></em></dt>
  <dd>
    Second value to be compared</dd>
</dl>
<h2 id="Description">Description</h2>
<p><span class="short_text" id="result_box" lang="en"><span><code>Object.is</code> is quite simliar to the === operator. In contrast the function however checks if two values are indistingushiable instead of just equal. This difference is only oberservable for two values, NaN and -0</span></span>.</p>
<h2 id="Examples">Examples</h2>
<pre class="brush:js;">
Object.is("foo", "foo");     // true
Object.is(window, window);   // true

Object.is("foo", "bar");     // false
Object.is([], []);           // false

var test = {a: 1};
Object.is(test, test)       // true

Object.is(null, null)       // true

// Special Cases
Object.is(0, -0);            // false
Object.is(-0, -0);           // true
Object.is(NaN, 0/0);         // true</pre>
<p>&nbsp;</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatNo}}</td>
        <td>
          <p>{{CompatGeckoDesktop("22")}}</p>
        </td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatGeckoDesktop("22")}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>
<p>&nbsp;</p>
Revert to this revision