Why are two identical objects not equal to each other?

前端 未结 9 657
广开言路
广开言路 2020-11-22 05:43

Seems like the following code should return a true, but it returns false.

var a = {};
var b = {};

console.log(a==b); //returns false
console.log(a===b); //         


        
9条回答
  •  清酒与你
    2020-11-22 06:01

    ===, the strictly equal operator for objects checks for identity.

    Two objects are strictly equal if they refer to the same Object.

    Those are two different objects, so they differ.

    Think of two empty pages of paper. Their attributes are the same, yet they are not the same thing. If you write something on one of them, the other wouldn't change.

提交回复
热议问题