Truthy and Falsy Things

In order to use flow control successfully, it’s important to understand which kinds of values are “truthy” and which kinds of values are “falsy.” Sometimes, values that seem like they should evaluate one way actually evaluate another.

Example 2.14: Values that evaluate to true

‘0’;
‘any string’;
[]; // an empty array
{}; // an empty object
1; // any non-zero number

Example 2.15: Values that evaluate to false

0;
”; // an empty string
NaN; // JavaScript’s “not-a-number” variable
null;
undefined; // be careful — undefined can be redefined!

Leave a comment