オブジェクト同士を比較できない理由
.js
const cat = {
type: 0
}
const chat = {
type: 0
}
console.log(cat == chat); // false
console.log(cat.prop === chat.prop); // true
cat == chat)
cat, chatそれぞれに入っているのは、あくまでオブジェクトへの参照になる
参照を比較しているため、当然falseが返る
なので、cat.prop === chat.prop
のように、オブジェクトの中身で比較する必要がある
MEMO
プリミティブ型では、値の比較を行い
オブジェクトでは参照の比較を行なっている