MDN’s new design is in Beta! A sneak peek: Redirect 1

This is an experimental technology, part of the Harmony (ECMAScript 6) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.


The method determines whether two values are the same value.


var isSame =, value2);


The first value to compare.
The second value to compare.

Description determines whether two values are the same value. Two values are the same if one of the following holds:

  • both undefined
  • both null
  • both true or both false
  • both strings of the same length with the same characters
  • both the same object
  • both numbers and
    • both +0
    • both -0
    • both NaN
    • or both non-zero and both not NaN and both have the same value

This is not the same as being equal according to the == operator. The == operator applies various coercions to both sides before testing for equality (resulting in such behavior as "" == false being true), but doesn't coerce either value.

This is also not the same as being equal according to the === operator.  The === operator (and the == operator as well) treats the number values -0 and +0 as equal, and it treats Number.NaN as not equal to NaN.

Examples"foo", "foo");     // true, window);   // true"foo", "bar");     // false[], []);           // false

var test = {a: 1};, test);       // true, null);       // true

// Special Cases, -0);            // false, -0);           // true, 0/0);         // true

Polyfill is a proposed addition to the ECMA-262 standard; as such it may not be present in all browsers. You can work around this by utilizing the following code at the beginning of your scripts. This will allow you to use when there is still no native support.

if (! { = function(v1, v2) {
    if (v1 === 0 && v2 === 0) {
      return 1 / v1 === 1 / v2;
    if (v1 !== v1) {
      return v2 !== v2;
    return v1 === v2;


Specification Status Comment
ECMAScript Language Specification 6th Edition (ECMA-262) Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 30.0.1599.114 22 (22) Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Not supported ? 22.0 (22) Not supported Not supported Not supported

See also

Document Tags and Contributors

 Last updated by: Sheppy,