Strict equality (===)
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thestrict equality (===
) operator checks whether its two operands areequal, returning a Boolean result. Unlike theequality operator,the strict equality operator always considers operands of different types to bedifferent.
Try it
console.log(1 === 1);// Expected output: trueconsole.log("hello" === "hello");// Expected output: trueconsole.log("1" === 1);// Expected output: falseconsole.log(0 === false);// Expected output: false
Syntax
js
x === y
Description
The strict equality operators (===
and!==
) provide theIsStrictlyEqual semantic.
- If the operands are of different types, return
false
. - If both operands are objects, return
true
only if they refer to thesame object. - If both operands are
null
or both operands areundefined
,returntrue
. - If either operand is
NaN
, returnfalse
. - Otherwise, compare the two operand's values:
- Numbers must have the same numeric values.
+0
and-0
are considered to be the same value. - Strings must have the same characters in the same order.
- Booleans must be both
true
or bothfalse
.
- Numbers must have the same numeric values.
The most notable difference between this operator and theequality(==
) operator is that if the operands are of different types, the==
operator attempts to convert them to the same type before comparing.
Examples
Comparing operands of the same type
js
"hello" === "hello"; // true"hello" === "hola"; // false3 === 3; // true3 === 4; // falsetrue === true; // truetrue === false; // falsenull === null; // true
Comparing operands of different types
js
"3" === 3; // falsetrue === 1; // falsenull === undefined; // false3 === new Number(3); // false
Comparing objects
js
const object1 = { key: "value",};const object2 = { key: "value",};console.log(object1 === object2); // falseconsole.log(object1 === object1); // true
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-equality-operators |