JavaScript Course
JavaScript
/
Beginner

Truthy & Falsy Values

Definition

In JavaScript, every value has an inherent boolean 'truthiness'. When evaluated in a boolean context (like an `if` statement), values are coerced to either `true` or `false`.

Explain Like I'm New

Imagine a nightclub bouncer asking 'Are you a real value?'. Almost everyone gets in (Truthy). But there is a strict blacklist of exactly 6 values that are rejected at the door (Falsy).

Real World Example

Checking if an array exists before mapping it: `if (users) { users.map(...) }` instead of checking `if (users !== undefined && users !== null)`.

Common Use Cases

  • •Short-circuit evaluation
  • •Simplified if-statements

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What are the 6 falsy values in JavaScript?

intermediate

  • Is an empty array `[]` truthy or falsy?

advanced

  • What is `document.all` and why is it falsy?

Flash Cards

Question

What are the 6 falsy values?

Click to reveal answer
Answer

`false`, `0`, `""` (empty string), `null`, `undefined`, and `NaN`. (Technically `0n` BigInt and `document.all` are also falsy).

Question

Is an empty array truthy or falsy?

Click to reveal answer
Answer

It is Truthy! In JavaScript, ALL objects and arrays are truthy, even if they are empty. To check if an array is empty, you must check its length: `if (arr.length > 0)`.