Beginner JavaScript Interview QuestionsBeginnerConcept
JavaScript · Question 11
What are truthy and falsy values in JavaScript?
Direct answer
Falsy values become false in a boolean context; all other values are truthy.
JavaScript automatically converts values to booleans in conditions such as if, while, and logical expressions. The small set of falsy values is worth memorizing.
- Falsy: false, 0, -0, 0n, an empty string, null, undefined, and NaN.
- Truthy: every other value, including empty arrays, empty objects, the string "0", and the string "false".
This means if ([]) { ... } runs because an empty array is still an object and therefore truthy.