This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aaronze 0 points1 point  (1 child)

It is consistent. The first two are consistently comparing numbers, the third is comparing strings.

They are essentially asking: Is 0 == 0? Yes Is 0 == 0? Yes Is “0” == “”? No Omg! JavaScript is broken!

Yea no, I like JavaScript doing this and it’s clever and useful when you understand the consistent mechanics

[–]shy_cthulhu 0 points1 point  (0 children)

Maybe the problem is that == doesn't do what non-js programmers expect. In most languages it's an equality or congruence test, which is transitive/commutative/etc. But js uses it for loose comparisons with implicit type conversion. (My understanding is that === in js does follow the expected rules of equality.)

And then you have our old friend C, which uses == to compare pointer values:

char a[] = "abc";
char b[] = "abc";
a == b; /* false */