In JavaScript, values are considered either “truthy” or “falsy” when evaluated in a Boolean context, such as in an if statement. Here is a list of all the falsy values and some common truthy values:
Falsy Values
There are exactly 8 falsy values in JavaScript:
false
- The Boolean valuefalse
.0
- The number zero.-0
- The number negative zero.0n
- The BigInt zero.""
- An empty string.null
- The absence of any value.undefined
- A variable that has been declared but not assigned a value.NaN
- The result of an invalid number operation (Not-a-Number).
Truthy Values
All values that are not falsy are considered truthy. Here are some common examples of truthy values:
true
- The Boolean valuetrue
.- Any non-zero number (e.g., 1, -1, 3.14).
- Any non-empty string (e.g.,
"hello"
, “0”,"false"
). - Any object (e.g.,
{}
,[]
,function() {}
). - Any non-zero BigInt (e.g.,
1n
,-1n
). Infinity
and-Infinity
.
Examples in Code
Here are some examples to illustrate truthy and falsy values in JavaScript: