How to check that two variables point to the same object? Meaning that if I mutate it—the value pointed to by both variables will change. In Python there is is operator, what about JavaScript?
How to check that two variables point to the same object? Meaning that if
Share
the strict equality operator (
===) will evaluate to true if references are the same without doing any type conversion:After shooting down two posts that have made the same mistakes, I think I should point out that it’s possible for
==to equate a reference type with a value type due to type conversion:AFAIK if you can guarantee that both variables are reference types,
==should work just fine, but that is so rarely the case that you’re better off sticking with strict comparison most of the time.