JavaScript has a concept of truthy and falsy values. These are values that behave as either or true
or false
, but aren't necessarily of the boolean type.
Examples of falsy values are:
false
- 0
- '' or "" (empty string)
null
undefined
NaN
Examples of truthy values are:
- Basically everything else
true
- '0'
- 'false'
- []
- {}
- function () {} (empty function)
- Most numbers, like 1 or 2 or 100 for example
- Strings that aren't empty