+ 1
Why does this evaluate to false?
var x ={age:24}; var y = x; var z ={age:24}; alert(y==(x==z)); Can’t work it out! So if I ran this as separate statements. And y==x evaluates to true, and z==x evaluates to false. But I can’t figure out why! Any help appreciated please! Thx in advance peeps :-)
2 Antworten
+ 7
Objects in js are comparated by reference, then, them are equals ONLY if either refer to same object (eg. dont matter if either have same key/value pairs)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
+ 1
Ah! fantastically useful advice!