This is a subject much covered in JavaScript programming annals. Here is a beginner’s link for those following in Fraffic’s taillights.
http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
This is from Douglas Crockford’s JavaScript: The Good Parts:
The if statement changes the flow of the program based on the value of the expression. The then block is executed if the expression is truthy; otherwise, the optional else branch is taken.
Here are the falsy values:
- false
- null
- undefined
- The empty string ”
- The number 0
- The number NaN
All other values are truthy, including true, the string ‘false’, and all objects.
