The strict equality 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
!==
) use the
Strict Equality Comparison Algorithm
to compare two operands.
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.
console.log("hello" === "hello"); // true
console.log("hello" === "hola"); // false
console.log(3 === 3); // true
console.log(3 === 4); // false
console.log(true === true); // true
console.log(true === false); // false
console.log(null === null); // true
console.log("3" === 3); // false
console.log(true === 1); // false
console.log(null === undefined); // false
const object1 = {
name: "hello"
}
const object2 = {
name: "hello"
}
console.log(object1 === object2); // false
console.log(object1 === object1); // true
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Equality operators' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Strict equality (
a === b
)
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持