Truth and Equality in JavaScript

This is a subject much covered in JavaScript programming annals. Here is a beginner’s link for those following in Fraffic’s taillights.

This is from Douglas Crockford’s JavaScript: The Good Parts:

For those who’ve never seen an ‘if’ statement in railroad diagram form

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.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s