Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Strict equality (===)

BaselineWidely available

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, returnfalse.
  • If both operands are objects, returntrue only if they refer to thesame object.
  • If both operands arenull or both operands areundefined,returntrue.
  • If either operand isNaN, returnfalse.
  • Otherwise, compare the two operand's values:
    • Numbers must have the same numeric values.+0 and-0are considered to be the same value.
    • Strings must have the same characters in the same order.
    • Booleans must be bothtrue or bothfalse.

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp