Back to JavaScript Notes
Topic #287

JavaScript Booleans

You will be able to explain JavaScript’s two Boolean values, predict how common values convert to true or false, and use Boolean conversion safely in conditions.

What it is

A Boolean is a primitive JavaScript value that can only be true or false. Booleans are the result of comparisons and are used to control program flow in statements such as if, while, and for.

JavaScript often needs a Boolean even when the value is not one. For example, if (username) converts username to a Boolean. This conversion is called coercion. The mental model is: “Is this value useful enough to count as true?”

The falsy values are:

  • false
  • 0
  • -0
  • 0n
  • ""
  • null
  • undefined
  • NaN

Everything else is truthy, including [], {}, "0", and "false". Related terms include truthy, falsy, Boolean object, and primitive Boolean.

Why it matters

  • Conditions like if (value) depend on Boolean coercion.
  • Logical operators such as &&, ||, and ! work with truthy and falsy values.
  • Boolean conversion helps normalize user input, such as checking whether a field is filled.
  • Understanding falsy values prevents bugs with empty strings, zero, null, and undefined.
  • Explicit Boolean values make APIs and state easier to reason about.

Syntax or steps

  1. Use Boolean(value) to convert any value to true or false.
  2. Use if (value) when you want to accept any truthy value.
  3. Use if (!value) when you want to catch falsy values.
  4. Use value === true or value === false when you need an exact Boolean.
Boolean("");        // false
Boolean("hello");   // true
Boolean(0);         // false
Boolean(1);         // true
Boolean([]);        // true
Boolean({});        // true

Example

const values = [true, false, 0, 1, "", "hello", null, undefined, NaN, [], {}, "0"];

for (const value of values) {
  console.log(String(value), Boolean(value));
}

const username = "";

if (username) {
  console.log("Welcome back!");
} else {
  console.log("Please sign in.");
}

const isAdmin = Boolean(username === "admin");
console.log(isAdmin);

Part-by-part explanation

The first loop tests many values and prints their Boolean conversion. Empty string, 0, null, undefined, and NaN become false. Non-empty strings, numbers other than zero, arrays, and objects become true.

The if (username) block checks whether username is truthy. Because username is "", it is falsy, so the else branch runs.

The expression username === "admin" already returns a Boolean, but wrapping it in Boolean() makes the intent explicit: store a true/false result.

Common mistakes

  • Assuming 0 or "" are truthy. They are falsy. If you need to allow zero or empty strings, check explicitly, such as value !== undefined.
  • Using new Boolean(false). That creates a Boolean object, and objects are truthy. Use Boolean(false) instead.
  • Confusing == with ===. Use === when you need exact Boolean comparison.
  • Using !value to mean “value is false.” It actually means “value is falsy,” which also includes 0, "", null, and undefined.

When to use it

Use implicit truthiness when you only care whether a value exists or is non-empty. Use explicit Boolean conversion when you need a clean true or false result. Use strict equality when you need to know whether a value is exactly a Boolean.

Pattern Use when Example
if (value) You want any truthy value if (name) { greet(); }
Boolean(value) You need a true/false result const hasName = Boolean(name);
value === false You need exact Boolean false if (enabled === false) { stop(); }

Practice

Guided exercise: create an array containing 0, "0", "", "hello", null, and undefined. Use Boolean() to print whether each value is truthy.

Expected output: 0, "", null, and undefined are false; "0" and "hello" are true.

Challenge: write a function called isFilled(value) that returns true only when value is a non-empty string. Hint: use typeof value === "string" and value.length > 0.

Quick check

Question: What does Boolean("false") return?

Answer: true, because "false" is a non-empty string, and non-empty strings are truthy.

Summary

JavaScript Booleans are simple: only true and false are Boolean values. Many other values become Boolean through coercion, with a small set of falsy values and everything else truthy.

Use truthiness for convenience, Boolean() for explicit conversion, and strict equality when exact Boolean values matter.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JavaScript Booleans – FAQs

Quick answers about learning JavaScript Booleans in JavaScript.

This free note from Coding Now Tech Institute explains JavaScript Booleans in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JavaScript Booleans, is 100% free with no signup required.
With focused practice, most students grasp JavaScript Booleans in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now