Truthy and Falsy Values

In this chapter

  • What Truthy Values in JavaScript
  • What Falsy Values in JavaScript

In JavaScript, a truthy value is a value that is considered true when encountered in a Boolean context. All values are truthy unless they are defined as falsy. That is, all values are truthy except false, 0, -0, 0n, "", null, undefined, and NaN.

JavaScript uses type coercion in Boolean contexts.

The following table provides a list of JavaScript falsy values:

ValueDescription
falseThe keyword false.
0, 0.0, 0x0The Number zero.
-0, -0.0, -0x0The Number negative zero.
0n, 0x0nThe BigInt zero.
"", '', ``Empty string value.
nullnull — the primitive value.
undefinedundefined — the primitive value.
NaNNaN — not a number.

Examples of falsy values in JavaScript (which will be coerced to true in boolean contexts, and thus execute the if block):

if (false) { // Not reachable } if (null) { // Not reachable } if (undefined) { // Not reachable } if (0) { // Not reachable } if (-0) { // Not reachable } if (0n) { // Not reachable } if (NaN) { // Not reachable } if ("") { // Not reachable }

Examples of falsy values in JavaScript (which will be coerced to true in boolean contexts, and thus execute the while block):

while (false) { // Not reachable } while (null) { // Not reachable } while (undefined) { // Not reachable } while (0) { // Not reachable } while (-0) { // Not reachable } while (0n) { // Not reachable } while (NaN) { // Not reachable } while ("") { // Not reachable }