r/programming • • Mar 26 '14

JavaScript Equality Table

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

331 comments sorted by

View all comments

-3

u/rjcarr Mar 26 '14

This doesn't seem that complicated to me. Basically, these are "falsey": false, 0, empty string, null, undefined, and NaN. Everything else is "truthy".

I think everything else flows from that with only a couple exceptions that I'm too lazy to look up.

And that said, definitely use === instead of coercive ==.

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.

→ More replies (1)