厳密等価 (===)

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.

厳密等価演算子 (===) は、二つのオペランドが等しいことを検査し、論理値で結果を返します。等価演算子とは異なり、厳密等価演算子はオペランドの型が異なる場合、常に異なるものと判断します。

試してみましょう

console.log(1 === 1);
// Expected output: true

console.log("hello" === "hello");
// Expected output: true

console.log("1" === 1);
// Expected output: false

console.log(0 === false);
// Expected output: false

構文

js
x === y;

解説

厳密等価演算子 (=== および !==) は、厳密等価比較アルゴリズムを使用して 2 つのオペランドを比較します。

  • オペランドの型が異なる場合は、 false を返します。

  • 両方のオペランドがオブジェクトである場合、同じオブジェクトを指している場合に限り true を返します。

  • 両方のオペランドが null または両方のオペランドが undefined であった場合は true を返します。

  • どちらかのオペランドが NaN であった場合は false を返します。

  • それ以外の場合は、2 つのオペランドの値を比較します。

    • 数値型は同じ値の数値である必要があります。 +0-0 は同じ値と見なされます。
    • 文字列型は同じ文字が同じ順序で並んでいる必要があります。
    • 論理型は両方が true であるか両方が false である必要があります。

この演算子と等価 (==) 演算子の最も顕著な違いは、オペランドの型が異なる場合、 == 演算子は比較前に同じ型に変換しようとすることです。

オペランドが同じ型である場合の比較

js
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

オペランドが異なる型である場合の比較

js
console.log("3" === 3); // false

console.log(true === 1); // false

console.log(null === undefined); // false

オブジェクトの比較

js
const object1 = {
  name: "hello",
};

const object2 = {
  name: "hello",
};

console.log(object1 === object2); // false
console.log(object1 === object1); // true

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-equality-operators

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Strict equality (a === b)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報