Truthy and Falsy Values

Updated · 6 min read
easyES2026javascriptbooleanstruthyfalsyinterview

A boolean is a value that is either true or false. But a JavaScript condition accepts any value, not just booleans: if ("Navika"), if (0) and if ([]) are all legal. JavaScript converts the value to a boolean first. Values that become true are called truthy; values that become false are called falsy. There are exactly eight falsy values, and learning them by heart prevents a large share of beginner and interview bugs.

In One Minute

  • The falsy values: false, 0, -0, 0n, "" (empty string), null, undefined, NaN.
  • Everything else is truthy, including "0", "false", " ", [], {} and every function.
  • Boolean(value) and !!value convert a value to a real boolean.
  • Truthiness is a shortcut. When 0 or "" are valid values, compare explicitly instead.

Booleans

Booleans come from comparisons and logical operators, or you can write them directly:

booleans.js▶ Try it
const isPaid = false;
const balance = 120;
 
console.log(typeof isPaid);
console.log(balance > 100);
console.log(balance > 100 && !isPaid);
Output
boolean
true
true

Name boolean variables so they read as yes-or-no questions: isPaid, hasDiscount, canRefund. Then if (isPaid) reads like English.

The Eight Falsy Values

ValueTypeWhy it is falsy
falsebooleanIt is false
0numberZero
-0numberNegative zero
0nbigintBigInt zero
""stringThe empty string (no characters)
nullnullDeliberately empty
undefinedundefinedNot set
NaNnumberNot a number
falsy.js▶ Try it
const values = [false, 0, -0, 0n, "", null, undefined, NaN];
 
for (const value of values) {
  if (value) {
    console.log(String(value), "is truthy");
  } else {
    console.log(String(value), "is falsy");
  }
}
Output
false is falsy
0 is falsy
0 is falsy
0 is falsy
 is falsy
null is falsy
undefined is falsy
NaN is falsy

Explanation: each value goes through if, and every one takes the else branch. String(-0) prints as 0, String(0n) as 0, and the empty string prints as nothing before " is falsy".

Everything Else Is Truthy

These surprise people because they look empty or false:

truthy.js▶ Try it
console.log(Boolean("0"));
console.log(Boolean("false"));
console.log(Boolean(" "));
console.log(Boolean([]));
console.log(Boolean({}));
console.log(Boolean(-1));
console.log(Boolean(function () {}));
Output
true
true
true
true
true
true
true

Explanation: a string is falsy only when it has zero characters: "0", "false" and " " (one space) all have characters. Every object is truthy, and an empty array or object is still an object. To test for an empty array, check its length: if (fees.length === 0).

Converting to a Boolean

WayExampleResult
Boolean(value)Boolean("Navika")true
!!value (double NOT)!!0false
Conditionif (value)converts automatically

!value converts and flips; !!value flips twice, leaving the plain boolean. Both forms are common; Boolean(value) reads more clearly, and it is handy with array methods: names.filter(Boolean) removes every falsy item.

filter-boolean.js▶ Try it
const names = ["Navika", "", "Srihitha", null, "Advitha", undefined];
console.log(names.filter(Boolean));
Output
['Navika', 'Srihitha', 'Advitha']

Where Truthiness Bites

Truthiness is a shortcut for "is there something here?". It goes wrong when 0 or "" are real values:

bite.js▶ Try it
function showBalance(balance) {
  if (balance) {
    return `Balance: $${balance}`;
  }
  return "No balance on file";
}
 
console.log(showBalance(120));
console.log(showBalance(0));
console.log(showBalance(undefined));
Output
Balance: $120
No balance on file
No balance on file

A student who owes nothing has a balance of 0, which is a real, known value. The truthy check treats it like a missing balance. The fix is to say what you mean:

fixed.js▶ Try it
function showBalance(balance) {
  if (balance === undefined || balance === null) {
    return "No balance on file";
  }
  return `Balance: $${balance}`;
}
 
console.log(showBalance(0));
console.log(showBalance(undefined));
Output
Balance: $0
No balance on file

In Practice

The Fee Tracker checks a form before saving. A name must be typed (empty means missing, so truthiness fits), but an amount of 0 must be rejected with its own message rather than treated as missing:

validate.js▶ Try it
function validate(form) {
  const name = form.name.trim();
  if (!name) return "Enter the student's name.";
 
  if (form.amount === "") return "Enter an amount.";
  const amount = Number(form.amount);
  if (Number.isNaN(amount)) return "The amount must be a number.";
  if (amount === 0) return "The amount can't be zero.";
  return `Saved $${amount} for ${name}.`;
}
 
console.log(validate({ name: "  ", amount: "50" }));
console.log(validate({ name: "Advitha", amount: "" }));
console.log(validate({ name: "Advitha", amount: "0" }));
console.log(validate({ name: "Advitha", amount: "50" }));
Output
Enter the student's name.
Enter an amount.
The amount can't be zero.
Saved $50 for Advitha.

Common Mistakes

Testing an array for emptiness with if (list). Always true. Use list.length.

Treating "0" or "false" from a form as false. They are non-empty strings, so they're truthy. Convert or compare: value === "true".

Using truthiness on numbers that can be zero. Balances, counts and indexes are often 0. Compare explicitly.

Using indexOf in a condition. if (names.indexOf("Navika")) is false when Navika is at index 0, and true when she isn't found (-1). Use names.includes("Navika").

Interview Corner

What are the falsy values in JavaScript?

false, 0, -0, 0n, "", null, undefined and NaN. Everything else is truthy, including "0", "false", [], {} and functions. (Browsers also have one legacy falsy object, document.all, kept for old pages.)

Is an empty array truthy?

Yes. All objects are truthy, regardless of contents. Check arr.length === 0 for emptiness. Note that [] == false is true because == converts the array to a number, which is a different rule from truthiness.

What does this print?

Show solution
puzzle.js▶ Try it
console.log(!!"0", !!0, !![], !!"");
Output
true false true false

"0" is a non-empty string (truthy), 0 is falsy, [] is an object (truthy), and "" is empty (falsy).

Practice

Challenge: Write hasItems(value) that returns true only for a non-empty array, and false for empty arrays, null, undefined and anything that isn't an array.

Show solution
has-items.js▶ Try it
function hasItems(value) {
  return Array.isArray(value) && value.length > 0;
}
 
console.log(hasItems([120]));
console.log(hasItems([]));
console.log(hasItems(null));
console.log(hasItems("abc"));
Output
true
false
false
false

Quick check: Truthy and falsy

3 questions
1Which value is falsy?
2What does Boolean(" ") return?
3What is the safe way to check that an array is empty?

Key Takeaways

Want to knowWrite
Is there an object?if (student)
Was text typed?if (name.trim())
Is a number positive?if (amount > 0)
Is the list empty?if (list.length === 0)
Is it missing?if (value == null) or value === undefined

Was this tutorial helpful?

Lesson 13 of 139