Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Truthy and Falsy

JavaScript converts values to Boolean in conditions and logical expressions. Most values are truthy; false, zero, the empty string, null, undefined, and NaN are falsy.

How it works

JavaScript converts an expression to a Boolean when it is used as a condition or with Boolean conversion. Falsy values include false, 0, -0, 0n, the empty string, null, undefined, and NaN; other values, including empty arrays and objects, are truthy.

Syntax

Boolean(value)

Key points

  • Truthiness is contextual: a value can be used directly as a condition without first being explicitly converted with Boolean().
  • The default rule is that values are truthy; only the language's defined falsy values convert to false.
  • The standard falsy set includes false, numeric zero forms, BigInt zero, the empty string, null, undefined, NaN, and the browser-specific document.all value.
  • An if condition, logical operator, or Boolean conversion can coerce a non-Boolean expression to a Boolean result for testing.
  • && processes operands left to right and short-circuits as soon as it encounters a falsy operand.
  • Logical operators preserve selected operand values, which lets expressions produce data such as a fallback or a guarded result.

Common mistakes

  • Logical operators return an operand rather than necessarily returning true or false: && stops at the first falsy operand, while || stops at the first truthy operand.

Example: Testing truthiness

const values = [false, 0, "", null, undefined, NaN, [], {}];

for (const value of values) {
  console.log(Boolean(value));
}

Boolean contexts convert values without changing the original value; objects and arrays are truthy, even when empty.

When to use it

Conditional checks

Run code only when a value is present or enabled.

Fallback selection with ||

Choose the first available value from several candidates.

Guarded evaluation with &&

Stop a computation when an earlier prerequisite is absent.

Interview questions

QWhat are truthy and falsy values in JavaScript?

A truthy value is converted to true in a Boolean context, while a falsy value is converted to false. Falsy values include false, 0, -0, 0n, the empty string, null, undefined, and NaN.

Follow-up: What does Boolean([]) return? It returns true because arrays are objects, and objects are truthy.

QHow does && use truthiness?

The && operator evaluates from left to right and returns the first falsy operand. If every operand is truthy, it returns the last operand, preserving that operand's original value.

Follow-up: What does 0 && "fallback" return? It returns 0 and does not evaluate the right operand because 0 is falsy.

QHow does || use truthiness?

The || operator evaluates from left to right and returns the first truthy operand. If none is truthy, it returns the last operand, so it is commonly used to select a fallback.

Follow-up: Why can || be unsuitable for defaulting a valid zero? Because 0 is falsy; use ?? when only null or undefined should trigger the fallback.

  • Logical operators
  • Logical NOT (!)
  • if...else
  • Boolean

Source: Logical operators - The Modern JavaScript Tutorial. Checked 2026-10-15.