In JavaScript variables, which are objects (including arrays), they actually refer to the collection. Therefore, when you write var x = { a: 2 } and var y = { a: 2 } , then x and y become references to two different objects. Therefore, x will not be equal to y . But, if you did y = x , then they are (because they will have the same link). But if you change any object, then the other will also be changed.
So, when dealing with objects and arrays by saying == , you check to see if these two links are the same. In this case, this is not so.
source share