Truthy
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."
Related Terms
Falsy
Falsy values are the six (well, seven) values in JavaScript that evaluate to false in a boolean context: false, 0, empty string, null, undefined, and NaN.
Footgun
A feature or tool that makes it really easy to shoot yourself in the foot — meaning it's easy to make a mistake that hurts you.
JavaScript
JavaScript is what makes websites actually DO stuff. HTML is the bones, CSS is the skin, and JavaScript is the muscles and brain.
TypeScript
TypeScript is JavaScript with a strict parent watching over it.