How to check if two vars have the same reference?

后端 未结 5 1333
借酒劲吻你
借酒劲吻你 2020-12-13 03:23

How can you check if two or more objects/vars have the same reference?

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 03:51

    You use == or === :

    var thesame = obj1===obj2;
    

    From the MDN :

    If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

提交回复
热议问题