+ 4
Why does this javascript return false?
var a={value:20}; var b={value:20}; alert(a==b); They're both the same, so shouldn't it return true?
5 Antworten
+ 26
You can't compare objects...
+ 7
"The reason for this is that internally JavaScript actually has two different approaches for testing equality. Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory."
src: http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html
+ 5
sees title...
BECAUSE IT CANT C#!!! 😂😂😂
honestly have no clue.... dont even know javascript, just wanted to make a pun
+ 1
Short and sweet. Thanks.
+ 1
Comparing objects ALWAYS returns false. If you want to compare the objects values, you have to write a function of your own.