Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if two vars have the same reference?

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

like image 627
clarkk Avatar asked Dec 03 '12 14:12

clarkk


People also ask

Can two variables refer to the same object Python?

Use the is operator to check if two variables reference the same object. Use the is operator to check two variables for identity and == to check for two variables for equality.

Can an object have more than one reference?

a doublelinked list may be a concrete example where you have multiple references to the same object.


1 Answers

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.

like image 198
Denys Séguret Avatar answered Sep 18 '22 13:09

Denys Séguret