What are falsy values in JavaScript?
The falsy values in JavaScript are 0
, 0n
, null
, undefined
, false
, NaN
, and the empty string ""
. They evaluate to false when coerced by JavaScript’s typing engine into a boolean value, but they are not necessarily equal to each other.
Published in
4 min readOct 7, 2019
Falsy values in JavaScript
“A falsy value is a value that is considered false when encountered in a Boolean context.” — Mozilla Developer Network
In JavaScript, there is a special list of following 7 values, which are called falsy values — they all evaluate to false in conditionals:
- the number
0
. (and -0) - the BigInt
0n
- the keyword
null
- the keyword
undefined
- the boolean
false
- the number
NaN
- the empty string
""
(equivalent to''
or``
)
Strictly speaking, you have to “coerce” (force) a falsy value to make it false
, for example by using Boolean()
or the ?
ternary operator.