JavaScript Interview Prep
Type System & Coercion

Truthy / Falsy

The Nightclub Bouncer

LinkedIn Hook

[] is truthy. {} is truthy. "0" is truthy. "false" is truthy. new Boolean(false) is truthy.

There are exactly 8 values in all of JavaScript that are falsy. Memorize those 8 and every if, every &&, every ||, every ternary becomes deterministic.

The real trap isn't the falsy list — it's using || for defaults when 0 or "" could be valid inputs. That's why ?? (nullish coalescing) exists, and why replacing || with ?? quietly fixes a class of bugs in production code.

In this lesson you'll learn the complete falsy list, the surprising truthies, how || and ?? differ, and why !!value is the shortest explicit boolean conversion in the language.

If an interviewer says "name every falsy value in JS" — after this lesson you'll list 8 without pausing.

Read the full lesson -> [link]

#JavaScript #InterviewPrep #TruthyFalsy #NullishCoalescing #Frontend #CodingInterview #WebDevelopment


Truthy / Falsy thumbnail


What You'll Learn

  • The complete list of 8 falsy values — and why everything else is truthy
  • The surprising truthies: [], {}, "0", "false", and boxed wrappers
  • When to use || vs ?? for default values, and the !!value idiom

The Nightclub Bouncer

Think of JavaScript as a nightclub bouncer. There's a very short guest list of people who are NOT allowed in (falsy values). Everyone else — no matter how weird — gets in (truthy).

The Complete Falsy Values List (8 Values)

// These are ALL the falsy values in JavaScript -- memorize them:
Boolean(false);     // false -- the literal boolean false
Boolean(0);         // false -- zero
Boolean(-0);        // false -- negative zero
Boolean(0n);        // false -- BigInt zero
Boolean("");        // false -- empty string (not " ", which is truthy!)
Boolean(null);      // false -- null
Boolean(undefined); // false -- undefined
Boolean(NaN);       // false -- Not a Number

The Falsy Table

+-------------+----------+--------------------------------+
| Value       | Type     | Why it's falsy                 |
+-------------+----------+--------------------------------+
| false       | boolean  | The literal false value        |
| 0           | number   | Zero                           |
| -0          | number   | Negative zero                  |
| 0n          | bigint   | BigInt zero                    |
| ""          | string   | Empty string                   |
| null        | object*  | Intentional absence            |
| undefined   | undefined| Not assigned                   |
| NaN         | number   | Invalid number                 |
+-------------+----------+--------------------------------+
* typeof null returns "object" due to a historical bug

Everything Else Is Truthy — Including These Gotchas

// THESE ARE ALL TRUTHY -- they surprise people:
Boolean([]);                  // true -- empty array is truthy!
Boolean({});                  // true -- empty object is truthy!
Boolean("0");                 // true -- non-empty string (even "0"!)
Boolean("false");             // true -- the STRING "false" is truthy
Boolean(" ");                 // true -- string with a space is truthy
Boolean(new Number(0));       // true -- object wrapper is truthy (even wrapping 0!)
Boolean(new Boolean(false));  // true -- object wrapper is truthy!
Boolean(Infinity);            // true
Boolean(-Infinity);           // true
Boolean([0]);                 // true -- non-empty array
Boolean(function(){});        // true -- functions are truthy

Practical Truthy/Falsy Usage

// Common pattern: default values with ||
const name = userInput || "Anonymous";

// Problem: 0 and "" are falsy but might be valid!
const port = userPort || 3000; // if userPort is 0, uses 3000!

// Modern fix: nullish coalescing (??) -- only null/undefined trigger default
const port2 = userPort ?? 3000; // if userPort is 0, keeps 0!

// Guard clauses
function processData(data) {
  if (!data) return; // catches null, undefined, "", 0, NaN
  // process...
}

// Double bang (!!) for explicit boolean conversion
const hasItems = !!myArray.length; // converts to true/false

The Tricky document.all

// document.all is the ONLY non-primitive falsy value (in browsers)
// It exists for legacy compatibility
typeof document.all;   // "undefined" (lies about its type!)
Boolean(document.all); // false (it's falsy!)
// But it still works as an object:
document.all[0]; // first element in the document

Truthy / Falsy visual 1


Common Mistakes

  • Using || to default numeric inputs like count || 10 — if the user passes 0, you'll overwrite it. Use ?? instead.
  • Checking if (arr) to test an empty array — arrays are always truthy regardless of length. Use arr.length or arr.length === 0.
  • Trusting new Boolean(false) — it's an object wrapper, so it's truthy. Never use new Boolean(...); use Boolean(x) or !!x instead.

Interview Questions

Q: Name all the falsy values in JavaScript.

There are 8: false, 0, -0, 0n (BigInt zero), "" (empty string), null, undefined, and NaN. Everything else is truthy.

Q: Is [] truthy or falsy? What about "0"?

Both are truthy. [] is an object (empty arrays are still objects, and all objects are truthy). "0" is a non-empty string (only the empty string "" is falsy). This is a common interview trap.

Q: What is the difference between || and ?? for defaults?

|| returns the right side for ANY falsy value (false, 0, "", null, undefined, NaN). ?? (nullish coalescing) only returns the right side for null or undefined. Use ?? when 0 or "" could be valid values.

Q: How do you explicitly convert a value to a boolean?

Either Boolean(value) or the double-bang idiom !!value. Never use new Boolean(value) — that creates an object wrapper, and every object is truthy, even new Boolean(false).


Quick Reference — Cheat Sheet

TRUTHY / FALSY -- QUICK MAP

The 8 falsy values (memorize):
  false | 0 | -0 | 0n | "" | null | undefined | NaN

Everything else is TRUTHY, including:
  []  {}  "0"  "false"  " "  -1  Infinity  fn(){}  new Boolean(false)

Defaults:
  ||   falls back on ANY falsy   (count || 10 breaks on 0)
  ??   falls back only on null / undefined   (prefer for numbers/strings)

Boolean conversion:
  Boolean(x)   -- explicit
  !!x          -- shortest
  new Boolean(x)  -- DON'T (object wrapper, always truthy)

Curiosity:
  document.all -- only non-primitive falsy value (legacy only)

Previous: Equality Operators -> The Strict vs Lenient Librarian Next: NaN, null, undefined -> The Three Empty Parking Spaces


This is Lesson 8.4 of the JavaScript Interview Prep Course — 14 chapters, 87 lessons.

On this page