This bit me today in a form validation function in a publicly-released app and marred what was otherwise a triumphant rewrite of someone else's steaming heap of cow dung (trust me on this one). I suppose there's a lesson there, for as well-intentioned as I was, but I'm not going to get into it.
As I discovered,
0is the same thing as an empty string (nothing?). It helps a little to see that
falseare all equal. But then, a little frightening that a string full of whitespace is also equal to
falsebut not equal to an empty string (transitive property, anyone?).
===(triple equals) operator is available if you want exact type and value matching:
0 === "": falseBut watch out! You probably want coercion most of the time (e.g. strings in input fields to ints). Just be aware.
For the curious there's plenty more info on the topic out there. A good reference is this matrix of == and === equalities.