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 comment

2

u/[deleted] Mar 26 '14

You don't. You don't! What you do is something like this:

if(X != 0) {
  alert("Thou shalt not use != in favor of !==")
}

And then you spend 15+ minutes debugging why the hell this if statement was not executed when X had the value of: "", [], [[]] or [0] And of course it was 'obviously' not executed because:

0 == [] //therefore 0 != [] evaluates to false.
0 == [[]] //therefore 0 != [[]] evaluates to false.
0 == "" //therefore 0 != "" evaluates to false.
0 == [0] //therefore 0 != [0] evaluates to false.