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.
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 values | Example |
|---|---|
| false | The boolean false itself |
| 0 | The number zero |
| -0 | Negative zero (rare, but falsy) |
| 0n | BigInt zero |
| "" (empty string) | A string with no characters |
| null | Intentional absence of value |
| undefined | Default absence of value |
| NaN | Not 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.
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:
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:
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":
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 stringUsing 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.
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:
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
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.
Frequently Asked Questions
What are all the falsy values in JavaScript?
Is an empty array truthy or falsy?
How do I check if a value is truthy or falsy?
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.
More in this topic
JavaScript While Loop Explained: A Complete Guide
A while loop repeats code as long as a condition stays true. Learn the syntax, see practical examples, and understand when a while loop is the right choice over a for loop.
JavaScript Loops Tutorial: for, while, do while
Loops let JavaScript repeat code without writing it twice. Learn the three core loop types, what each one does, and when to choose one over another.
How to Loop Through Arrays Using JS for Loops Guide
Looping through arrays is the most practical use of JavaScript for loops. Learn how to access each element by index, avoid off-by-one errors, and choose between for, for...of, and forEach.