Skip to content

JavaScript Tutorial Conditions

JavaScript Truthy and Falsy Values

Lesson 44 of 258 2 min read By Deepak Paswan Updated Oct 4, 2026

In a condition like if (value), JavaScript turns the value into true or false. Values that become false are falsy. Everything else is truthy.

The falsy values

There are only a handful:

ValueDescription
falsethe boolean
0, -0, 0nzero (number and BigInt)
""the empty string
nullno value
undefinednot set
NaNnot a number

Everything else is truthy, including these surprises:

script.js
JS
console.log(Boolean("0"));       // → true   (non-empty string)
console.log(Boolean("false"));   // → true
console.log(Boolean([]));        // → true   (empty array)
console.log(Boolean({}));        // → true   (empty object)
console.log(Boolean(-1));        // → true

An empty array is truthy. To check for an empty array, test its length.

script.js
JS
const items = [];

if (items) {
  console.log("this runs, even though the array is empty");
}
if (items.length === 0) {
  console.log("the array is empty"); // → the array is empty
}

Useful: checking for text

script.js
JS
function greet(name) {
  if (name) {
    return `Hello, ${name}`;
  }
  return "Hello, stranger";
}

console.log(greet("Maya")); // → Hello, Maya
console.log(greet(""));     // → Hello, stranger
console.log(greet());       // → Hello, stranger

The trap: zero

When 0 or "" is a valid value, a plain truthiness check is wrong.

script.js
JS
function showCount(count) {
  if (count) {
    return `${count} items`;
  }
  return "No count";
}

console.log(showCount(0)); // → No count   (probably not what you wanted)

Be explicit: if (count !== undefined), or use ??, see Nullish Coalescing.

Converting on purpose

Boolean(x) and !!x convert any value to a real boolean, as in Booleans.

lightbulb
When in doubt, be explicit
if (items.length > 0) is clearer than if (items.length), even though both work. Clear code beats short code.