Why {} != ( {} ) in JavaScript?

前端 未结 2 1562
闹比i
闹比i 2020-11-27 21:10

It\'s commonly known that {} is shorter way to define an object like [] is for an array.

But now I am wondering why:

{} !=          


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 21:31

    {} != {} is true because both {}'s are completely different objects. However, variables that are referencing the same object hold equality:

    ​var a = {},
        b = a;
    
    assert( a == b )​
    

提交回复
热议问题