Strict equality (===)
Baseline Widely 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.
In this article
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: falseSyntax
js
x === yDescription
The strict equality operators (=== and!==) provide theIsStrictlyEqual semantic.
- If the operands are of different types, return
false. - If both operands are objects, return
trueonly if they refer to thesame object. - If both operands are
nullor both operands areundefined,returntrue. - If either operand is
NaN, returnfalse. - Otherwise, compare the two operand's values:
- Numbers must have the same numeric values.
+0and-0are considered to be the same value. - Strings must have the same characters in the same order.
- Booleans must be both
trueor 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; // trueComparing operands of different types
js
"3" === 3; // falsetrue === 1; // falsenull === undefined; // false3 === new Number(3); // falseComparing objects
js
const object1 = { key: "value",};const object2 = { key: "value",};console.log(object1 === object2); // falseconsole.log(object1 === object1); // trueSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-equality-operators> |