How to check if two vars have the same reference?

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

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

5条回答
  •  [愿得一人]
    2020-12-13 03:48

    For reference type like objects, == or === operators check its reference only.

    e.g

    let a= { text:'my text', val:'my val'}
    let b= { text:'my text', val:'my val'}
    

    here a==b will be false as reference of both variables are different though their content are same.

    but if I change it to

    a=b
    

    and if i check now a==b then it will be true , since reference of both variable are same now.

提交回复
热议问题