r/programming • • Mar 26 '14

JavaScript Equality Table

http://dorey.github.io/JavaScript-Equality-Table/
809 Upvotes

331 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Mar 26 '14

Wrong, my brother in code. I too once thought like you did. However, as evidenced by the table when comparing two things that are falsy, they are not always considered equal. This is what the article is about, the equality operator, not the things that truthy are or are not falsy.
Sure the two falsy values null and undefined equal eachother. But the falsy value 0 does not equal null.

0

u/[deleted] Mar 26 '14

[deleted]

1

u/[deleted] Mar 26 '14

That is a comparison between two operands of the same type. The key problem here is comparison between different types.

1

u/mrkite77 Mar 26 '14

so change that to 5.0f and it's still the case. C-based languages coerce ints and floats and doubles and characters.

Here's a famous example:

int a = 16777217;
float b= 16777216.0f;
if (a == b) printf("holy shit, %d == %f?\n",a,b);

run that and you get: "holy shit, 16777217 == 16777216.000000?"