Truthy & Falsy Values0%

Truthy & Falsy Values

Beginner12 min read•Updated: Jul 11, 2026
Study Materials

Truthy & Falsy Values in JavaScript

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).


1. The Falsy Values in JavaScript

Out of the billions of values possible in JavaScript, there are only 8 falsy values. Everything else in the entire language is truthy!

Visual Architecture Blueprint
+-----------------------------------------------------------------------------+
|                      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!


2. Common Truthy Surprises

Beginners frequently get tripped up by values that seem "empty" or "zero-like" in English, but are completely truthy in JavaScript:

ValueTruthinessWhy 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

The Empty Array Trap:

JavaScript
const items = [];
 
// ❌ BAD: [] is truthy, so this will ALWAYS execute!
if (items) {
console.log("Items exist!"); // Runs even when array is empty!
}
 
// ✅ CORRECT: Check the length!
if (items.length > 0) {
console.log("Items exist!");
}

3. Explicit Boolean Conversion

You can inspect the truthiness of any value in the console using two methods:

JavaScript
// Method 1: Boolean() function
console.log(Boolean("")); // false
console.log(Boolean("hello"));// true
console.log(Boolean(0)); // false
console.log(Boolean([])); // true
 
// Method 2: Double NOT (!!) operator
console.log(!!null); // false
console.log(!!123); // true

4. Truthy Values in Conditional Logic

JavaScript
function greetUser(username) {
if (username) {
console.log(`Welcome back, ${username}!`);
} else {
console.log("Welcome, Guest!");
}
}
 
greetUser("Sumit"); // "Welcome back, Sumit!"
greetUser(""); // "Welcome, Guest!" (empty string is falsy)
greetUser(null); // "Welcome, Guest!" (null is falsy)

Interactive Quiz

Practice Quiz

Question 1
How many falsy values exist in modern JavaScript?
Question 2
What is the truthiness of an empty array [] in an if condition?
Question 3
What does Boolean("0") evaluate to?
Question 4
Which of the following values is FALSY?
Question 5
How do you safely test whether an array named users actually has elements in it?
Next Lesson

For Loop

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Switch StatementsFor Loop

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext