Truthy and Falsy Values

JavaScript converts values to boolean in contexts such as if, logical operators, and conditional expressions. Falsy values include false, 0, -0, 0n, "", null, undefined, and NaN. Everything else is truthy, including empty arrays and empty objects.

This distinction is important because developers often incorrectly assume that an empty array or object is falsy.

Truthy Does Not Mean Non-Empty
if ([]) {
  console.log('empty array is truthy');
}

if ({}) {
  console.log('empty object is truthy');
}
💡 Objects are truthy regardless of whether they contain properties or elements.
Key Takeaways
  • Empty arrays and objects are truthy.
  • Falsy is a specific set of values, not a general concept of emptiness.
  • Use explicit checks when zero, empty strings, or null-like values have different meanings.
Knowledge Check

Which value is falsy?