Skip to content

Truthy

Easy — everyone uses thisFrontend

ELI5 — The Vibe Check

In JavaScript, truthy means 'not technically true, but close enough.' The number 42 is truthy. The string 'hello' is truthy. An empty array is truthy (yes, really). Basically everything except false, 0, empty string, null, undefined, and NaN is truthy. It's JavaScript's way of saying 'sure, that works as a boolean, I guess.'

Real Talk

A truthy value is any value that evaluates to true in a boolean context. In JavaScript, all values are truthy except falsy values (false, 0, -0, 0n, '', null, undefined, NaN). Truthy/falsy evaluation is used in conditional statements, logical operators, and type coercion. Understanding truthy/falsy is essential for avoiding subtle bugs in JavaScript/TypeScript.

Show Me The Code

// Truthy values
if ('hello') console.log('truthy')  // runs
if (42) console.log('truthy')       // runs
if ([]) console.log('truthy')       // runs (empty array is truthy!)
if ({}) console.log('truthy')       // runs (empty object is truthy!)

// Common pattern: default values
const name = userInput || 'Anonymous'  // falsy check
const name = userInput ?? 'Anonymous'  // nullish check (preferred)

When You'll Hear This

"An empty array is truthy in JavaScript — that trips everyone up." / "Use nullish coalescing instead of relying on truthy checks."

Made with passive-aggressive love by manoga.digital. Powered by Claude.