What Are Truthy and Falsy Values in JavaScript

Every JavaScript value is either truthy or falsy. Learn the 8 falsy values, how truthy/falsy works in conditionals, and how to use this behavior safely.

5 min read

Truthy and falsy JavaScript values describe the inherent boolean nature every value has. When used in a place that expects a boolean, like an if statement or a logical operator, every value is either truthy or falsy.

A truthy value behaves like true. A falsy value behaves like false.

There are exactly 8 falsy values in JavaScript. If you memorize this short list, you will know how any value behaves in a conditional context. Everything that is not on this list is truthy.

The 8 falsy valuesExample
falseThe boolean false itself
0The number zero
-0Negative zero (rare, but falsy)
0nBigInt zero
"" (empty string)A string with no characters
nullIntentional absence of value
undefinedDefault absence of value
NaNNot a Number

Every other value is truthy. This includes surprising cases like empty arrays, empty objects, the string "false", the string "0", negative numbers, and the value Infinity. None of these are on the falsy list, so they are all truthy.

How Falsy Works in Conditionals

When you put a value in an if statement, JavaScript converts it to boolean behind the scenes. Falsy values skip the if block. Truthy values enter it.

javascriptjavascript
let username = "";
 
if (username) {
  console.log("Hello, " + username);
} else {
  console.log("No username provided");
}

The console prints "No username provided" because an empty string is falsy, so the if condition evaluates to false. This is a common pattern for checking whether a user filled out a form field.

All 8 falsy values behave the same way in conditionals:

javascriptjavascript
if (0)        { console.log("runs"); } else { console.log("skipped"); }
if (null)     { console.log("runs"); } else { console.log("skipped"); }
if (undefined){ console.log("runs"); } else { console.log("skipped"); }
if (NaN)      { console.log("runs"); } else { console.log("skipped"); }
if ("")       { console.log("runs"); } else { console.log("skipped"); }

Every one of these prints "skipped" because each value is falsy. Replace the condition with any truthy value like 1, "hello", or an empty array, and the if block runs instead.

Common Surprises with Truthy Values

Several values that look empty or false are actually truthy. Knowing these exceptions prevents bugs where you expect a falsy check to work but it does not.

An empty array is truthy. If you want to check whether an array has items, use its length property instead of the array itself:

javascriptjavascript
let items = [];
 
if (items) {
  console.log("This runs! Empty arrays are truthy");
}
 
if (items.length > 0) {
  console.log("This does not run. Length is 0");
}

An empty object is also truthy. The same principle applies: check Object.keys(obj).length if you need to know whether an object has properties. The object itself is always truthy regardless of its contents.

The string "false" is truthy because it is a non-empty string. Only an empty string is falsy. Any string with at least one character is truthy, even if that character is a space, a zero, or the word "false":

javascriptjavascript
if ("false") { console.log("runs"); } // truthy: non-empty string
if ("0")     { console.log("runs"); } // truthy: non-empty string
if (" ")     { console.log("runs"); } // truthy: non-empty string

Using Falsy for Default Values

The logical OR operator is commonly used with falsy values to provide defaults. It returns the first truthy value it encounters, which makes it perfect for fallback values.

javascriptjavascript
function greet(name) {
  let displayName = name || "Guest";
  console.log("Hello, " + displayName);
}
 
greet("Alex"); // "Hello, Alex"
greet("");     // "Hello, Guest" (empty string is falsy)
greet();       // "Hello, Guest" (undefined is falsy)

The expression name || "Guest" evaluates to the first truthy value. If name is truthy, it is used directly. If name is falsy, the fallback "Guest" is used instead.

This pattern has a limitation: it treats all falsy values the same way. An empty string, the number 0, and false are all valid values that might be intentionally set. The nullish coalescing operator provides a stricter alternative that only falls back for null and undefined:

javascriptjavascript
let count = 0;
console.log(count || 10);  // 10 (0 is falsy, fallback used)
console.log(count ?? 10);  // 0 (0 is not null or undefined)

Use OR when you want to catch all falsy values. Use nullish coalescing when zero, empty strings, and false are valid values that should pass through.

For more on how boolean coercion works in different contexts, see the implicit vs explicit type conversion guide. To understand the coercion rules for other operators, read the type coercion guide.

Rune AI

Rune AI

Key Insights

  • Only 8 values are falsy: false, 0, -0, 0n, '', null, undefined, NaN.
  • Everything else is truthy, including empty arrays and empty objects.
  • if statements, while loops, and logical operators coerce values to boolean.
  • Use the OR operator (||) for default values when a value might be falsy.
  • Use the nullish coalescing operator (??) when only null or undefined should fall back.
RunePowered by Rune AI

Frequently Asked Questions

What are all the falsy values in JavaScript?

There are exactly 8 falsy values: false, 0, -0, 0n (BigInt zero), '' (empty string), null, undefined, and NaN. Every other value in JavaScript is truthy, including empty arrays [], empty objects {}, and the string 'false'.

Is an empty array truthy or falsy?

An empty array [] is truthy. This surprises beginners because an empty array seems like it should be empty. But arrays are objects, and all objects are truthy, including empty ones. Check array length instead of the array itself.

How do I check if a value is truthy or falsy?

Use Boolean(value) for an explicit conversion, or !!value as a shorthand that converts to boolean. In practice, most developers use the value directly in an if statement and let JavaScript coerce it to boolean automatically.

Conclusion

There are exactly 8 falsy values in JavaScript. Everything else is truthy. This simple rule drives conditional logic, default values, and short-circuit evaluation. Knowing the falsy list by heart helps you predict how any value will behave in a boolean context.