Skip to main content

Falsy vs Truthy and Nullish

In javascript all the literal values can be assigned a truthy or a falsy can be assigned. This truthy and falsy values would have an impact on the program when it is encountered or evaluated in a boolean context (Usually if statements or for loops).

Easy to remember rule is to know which literals are falsy.

In JS the following values are considered falsy.

false, 0, -0, 0n, "", null, undefined, and NaN

Also document.all is the only property in JS considered to be falsy.

All the other values are considered truthy in JS.

In JS nullish values are

null, undefined

They are also falsy.