Join my Laravel for REST API's course on Udemy 👀

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:

ValueType
falseBoolean
'', "", ``String
0Number
-0Number
NaNNumber
0nBigInt
nullObject
undefinedUndefined
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.