The ===
operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
The ===
operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
x === y
The strict equality operators (===
and !==
) provide the IsStrictlyEqual semantic.
false
.true
only if they refer to the same object. null
or both operands are undefined
, return true
. NaN
, return false
.+0
and -0
are considered to be the same value. true
or both false
. The most notable difference between this operator and the equality (==
) operator is that if the operands are of different types, the ==
operator attempts to convert them to the same type before comparing.
"hello" === "hello"; // true "hello" === "hola"; // false 3 === 3; // true 3 === 4; // false true === true; // true true === false; // false null === null; // true
"3" === 3; // false true === 1; // false null === undefined; // false 3 === new Number(3); // false
const object1 = { key: "value", }; const object2 = { key: "value", }; console.log(object1 === object2); // false console.log(object1 === object1); // true
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 | ||
Strict_equality |
1 | 12 | 1 | 4 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 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/Operators/Strict_equality