JavaScript 厳密不等価演算子 (!==)でオブジェクトを比較するサンプル

環境
Windows 10 home 64bit
Google Chrome 107.0.5304.122

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

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const cityA = {
city: "tokyo"
}
const cityB = {
city: "oosaka"
}
console.log(cityA !== cityB); // true
console.log(cityA !== cityA); // false
const cityA = { city: "tokyo" } const cityB = { city: "oosaka" } console.log(cityA !== cityB); // true console.log(cityA !== cityA); // false
const cityA = {
  city: "tokyo"
}

const cityB = {
  city: "oosaka"
}

console.log(cityA !== cityB);  // true
console.log(cityA !== cityA);  // false

実行結果
> true
> false

JavaScript

Posted by arkgame