In JavaScript, every single value has an inherent boolean truth value. When any non-boolean value is evaluated in a boolean context (like an if condition or logical operator), JavaScript automatically coerces it into either true (truthy) or false (falsy).
Out of the billions of values possible in JavaScript, there are only 8 falsy values. Everything else in the entire language is truthy!
+-----------------------------------------------------------------------------+ | THE 8 FALSY VALUES IN JAVASCRIPT | +-----------------------------------------------------------------------------+ | 1. false : The boolean literal false | | 2. 0 : The number zero | | 3. -0 : Negative zero | | 4. 0n : BigInt zero | | 5. "" (or '' or ``) : Empty string with zero length | | 6. null : The null primitive | | 7. undefined : The undefined primitive | | 8. NaN : "Not a Number" invalid arithmetic result | +-----------------------------------------------------------------------------+
If a value is NOT on this exact list of 8, it is 100% TRUTHY!
Beginners frequently get tripped up by values that seem "empty" or "zero-like" in English, but are completely truthy in JavaScript:
| Value | Truthiness | Why is it Truthy? |
|---|---|---|
"0" | Truthy! | It is a string containing a character (length = 1) |
"false" | Truthy! | It is a non-empty string |
" " (whitespace) | Truthy! | Contains space character (length = 1) |
[] (Empty Array) | Truthy! | All objects and arrays in JS are truthy! |
{} (Empty Object) | Truthy! | All objects in JS are truthy! |
function(){} | Truthy! | Functions are objects, always truthy |
You can inspect the truthiness of any value in the console using two methods:
[] in an if condition?Boolean("0") evaluate to?users actually has elements in it?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Switch Statements | For Loop |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.