JavaScript Truthy and falsy

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

In boolean contexts, a value is falsy if it is false, 0, -0, 0n, "", null, undefined, or NaN. Everything else is truthy—including [] and {}.

JavaScript Syntax

JavaScript
console.log(Boolean(0));
console.log(Boolean(""));
console.log(Boolean([]));
console.log(Boolean("0"));
Try it Editor

How It Works

  1. 0 and "". Falsy.
  2. [] and "0". Truthy.

Examples

Example 1 — if checks

Branch on truthiness.

JavaScript
if ("hi") console.log("yes");
if (0) console.log("no");
Try it Editor

How It Works

  1. Non-empty string is truthy.

Example 2 — || default pitfall

0 is replaced.

JavaScript
const n = 0 || 10;
console.log(n);
Try it Editor

How It Works

  1. Use ?? to keep 0.

Example 3 — Prefer ?? for nullish

Only null/undefined.

JavaScript
console.log(0 ?? 10);
Try it Editor

How It Works

  1. 0 is kept.

Frequently Asked Questions

No. Empty arrays and objects are truthy.
Use Boolean(value) or !!value.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful