Nasi wolontariusze nie przetłumaczyli jeszcze tego artykułu na język Polski. Dołącz do nas i pomóż go przetłumaczyć!
Można także przeczytać artykuł w języku: English (US).

The method determines whether two values are the same value.

Syntax, value2);


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

Return value

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

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 in the same order
  • 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 (if they are not the same Type) 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 treats Number.NaN as not equal to NaN.

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

var foo = { a: 1 };
var bar = { a: 1 };, foo);         // true, bar);         // false, null);       // true

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


if (! { = function(x, y) {
    // SameValue algorithm
    if (x === y) { // Steps 1-5, 7-10
      // Steps 6.b-6.e: +0 != -0
      return x !== 0 || 1 / x === 1 / y;
    } else {
      // Step 6.a: NaN == NaN
      return x !== x && y !== y;


Specification Status Comment
ECMAScript Latest Draft (ECMA-262)
The definition of '' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of '' in that specification.
Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic supportChrome Full support 30Edge Full support 12Firefox Full support 22IE No support NoOpera Full support YesSafari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support 9Samsung Internet Android Full support Yesnodejs Full support 0.10


Full support  
Full support
No support  
No support

See also