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?