Reputation: 2595
I was looking at clause 11.9.6 of ES5 trying to figure out why [1,2,3] === [1,2,3] returns false.
The code:
a = [1,2,3]
b = [1,2,3]
a === b // false
Relevant rules for the strict equality comparison algo:
x === y
(1) If Type(x) is different from Type(y), return false.
...
...
...
(7) Return true if x and y refer to the same object. Otherwise return false.
Any ideas why an interpreter returns false?
Upvotes: 1
Views: 197
Reputation: 7618
a
and b
are two different objects, they just happen to have the same Number values in them. If you did a[0] = 42;
then b[0]
would still equal 1.
Upvotes: 4
Reputation: 4983
(7) Return true if x and y refer to the same object. Otherwise return false.
-they doesn't refer to the same object.
Upvotes: 0
Reputation: 39354
It looks like your a
and b
refer to different objects. They might each contain the same value and are instances of the same class, but you can change one and the other stays the same.
Upvotes: 0