How to check if two vars have the same reference?

clarkk picture clarkk · Dec 3, 2012 · Viewed 39.7k times · Source

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

Answer

Denys Séguret picture Denys Séguret · Dec 3, 2012

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.