Why are two identical objects not equal to each other?

前端 未结 9 688
广开言路
广开言路 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条回答
  •  旧时难觅i
    2020-11-22 06:04

    This is a workaround: Object.toJSON(obj1) == Object.toJSON(obj2)

    By converting to string, comprasion will basically be in strings

提交回复
热议问题