Back to all posts

2026-04-27

JavaScript falsy values and Boolean casting

Falsy values are predictable, but wrapping values in strings can change your Boolean result.

JavaScript has a small set of falsy values:

  • undefined
  • null
  • false
  • 0, -0, NaN
  • "" (empty string)

Quick examples:

Boolean(false); // false
Boolean(""); // false
Boolean("false"); // true

The key point: "false" is a non-empty string, so it is truthy.

Use explicit parsing when your data comes from query params, forms, or APIs:

function parseBoolean(value) {
  return value === "true";
}

Avoid relying on implicit casting when the meaning of true/false is important.