H.dev

The Boolean Object

True or False

A Boolean represents one of two values: true or false. While we usually use primitive booleans (e.g., let isActive = true), JavaScript technically has a Boolean object that acts as a wrapper.

The Boolean() Function

You can use the Boolean() function to find out if an expression (or a variable) is true or false.

console.log(Boolean(10 > 5)); // true
console.log(Boolean(10 < 5)); // false

Truthy and Falsy Values

In JavaScript, you don't just evaluate true and false. EVERY single value in JavaScript inherently evaluates to true ("truthy") or false ("falsy") when placed in a boolean context (like an if statement).

Falsy Values: There are only 6 falsy values in JavaScript. If you memorize these, everything else is truthy!

  1. false
  2. 0 (Zero)
  3. "" (Empty string)
  4. null
  5. undefined
  6. NaN
let name = ""; // Empty string is falsy

if (name) {
    console.log("We have a name!");
} else {
    console.log("Name is missing!"); // This runs!
}

Truthy Values: Everything that is not in the falsy list above is truthy.

Boolean("Himanshu"); // true (Non-empty string)
Boolean(42);         // true (Non-zero number)
Boolean([]);         // true (Empty array is truthy!)
Boolean({});         // true (Empty object is truthy!)

💡 Himanshu's Tip:

When checking if an array has items, never do if (myArray). Because an empty array is "truthy", that statement will always run! Instead, check its length: if (myArray.length > 0).

Interview Questions

  1. Name at least 4 of the 6 "falsy" values in JavaScript.
  2. Is an empty array [] considered truthy or falsy?
  3. What is the difference between null and undefined when evaluated in a boolean context?

Design & Developed by Himanshu Dubey © 2026