What are `falsy` values in JavaScript
April 7, 2022 ‐ 1 min read
While learning JavaScript you may have come across something like "value X is falsy". This relates to how the value is evaluated in a Boolean context, which is mainly in if-statements but also when casting to a boolean value.
The JavaScript values that evaluate to false
in a Boolean context are:
Value | Type |
---|---|
false | Boolean |
'' , "" , `` | String |
0 | Number |
-0 | Number |
NaN | Number |
0n | BigInt |
null | Object |
undefined | Undefined |
document.all (Don't ask me why) | HTMLAllCollection |
Notice here that empty arrays and empty objects are not considered falsy.
If there is falsy, what about truthy
Obviously when there are falsy values, there must be truthy values too. Which, logically, are values that evaluate to true
in a Boolean context. These truthy values are just all the other values which are not considered falsy.