r/programming • • Mar 26 '14

JavaScript Equality Table

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

331 comments sorted by

View all comments

24

u/[deleted] Mar 26 '14

Or, the definition of insanity.

41

u/qgustavor Mar 26 '14

Did you mean: PHP

10

u/bp3959 Mar 26 '14

Is this really that difficult of a thing to understand? When you use == it does automatic type conversion which is why you get weird results sometimes, this behavior is well documented and believe it or not it actually makes sense for a loose comparison+type conversion.

If you don't want any of this, use ===, wow so difficult.

2

u/frej Mar 26 '14 edited Apr 09 '14

It's not obvious and leads to hard to find errors.

Or! Think about why it's reasonable, as a default, to do boolean logic between different types.

2

u/Nanobot Mar 26 '14

Exactly. In the cases where you should be using ==, the conversions are generally helpful and intuitive. The cases where they aren't are the cases where you should have been using === anyway.

If it helps, think of === as the standard equality operator, and == is more like a shortcut operator that saves some manual type logic and conversion work. Like any shortcut, you should understand what it does before you use it.

12

u/Poltras Mar 26 '14

What about other operators where an === equivalent doesn't exist? Like +, <, ...

→ More replies (6)
→ More replies (2)
→ More replies (12)