JavaScript Boolean

Beginner
8 min read
Updated: Nov 2026
3 examples
true and false

Definition and Usage

Boolean is a JavaScript primitive type with exactly two values: true and false. A primitive is a plain value, such as true, 42, or "hi", and not an object. Booleans answer yes-or-no questions: Is the user logged in? Is the cart empty? Is 5 bigger than 3?

Comparisons such as 5 > 3 give a Boolean, and if, while, and the ? : operator all use one to choose what happens next. The typeof of a Boolean is "boolean". Booleans have been part of JavaScript since its first versions, so they work in every browser and in every version of Node.js.

Write true and false in lowercase.

True and TRUE are not Booleans. JavaScript reads them as variable names and throws a ReferenceError.

Three Ways to Get a Boolean

Write the literal true or false, compare two values, or convert any value with the Boolean() function. The third way, new Boolean(), makes an object, so do not use it. The comments show each result.

JavaScript
const a = true;                  // a Boolean literal
const b = Boolean(1);            // conversion: a plain (primitive) Boolean
const c = new Boolean(false);    // a wrapper object (avoid it)
typeof a;                        // "boolean"
typeof b;                        // "boolean"
typeof c;                        // "object"
5 > 3;                           // true (comparisons give Booleans)
Boolean();                       // false (no argument)
True;                            // ReferenceError (the keyword is lowercase)

new Boolean(false) Is Truthy

A wrapper object is an object that holds a plain value inside. new Boolean(false) builds one. It looks like false but it is an object, and every object is truthy (truthy means “counts as true in an if”). So if (new Boolean(false)) runs its block. Boolean(false) without new is the plain false.

JavaScript
const flag = new Boolean(false);
typeof flag;                     // "object"
flag ? "truthy" : "falsy";       // "truthy" (an object is always truthy)
flag.valueOf();                  // false
flag == false;                   // true
flag === false;                  // false
Boolean(false);                  // false (no new: a plain primitive)
Boolean(flag);                   // true
Boolean(flag.valueOf());         // false

To get the plain value out of a wrapper, call valueOf(). Better still, never create wrappers: use true, false, or Boolean(value).

Truthy and Falsy Values

Anywhere JavaScript expects a Boolean, it converts the value you give it. Falsy values become false. Truthy values become true. There are only eight falsy values:

Falsy valueTypeNote
falseBooleanThe Boolean false itself.
0NumberZero.
-0NumberNegative zero, a rare cousin of zero.
0nBigIntZero as a BigInt.
""StringThe empty string (also '').
nullnull“No value” on purpose.
undefinedundefinedA variable that has no value yet.
NaNNumber“Not a number”, the result of a failed calculation.

Everything else is truthy. That includes surprises such as the text "false", the text "0", an empty array [], and an empty object {}. (Old browsers also treat the special document.all object as falsy. You will almost never meet it.)

JavaScript
Boolean(false);        // false
Boolean(0);            // false
Boolean(-0);           // false
Boolean(0n);           // false
Boolean("");           // false
Boolean(null);         // false
Boolean(undefined);    // false
Boolean(NaN);          // false
JavaScript
Boolean("false");           // true
Boolean("0");               // true
Boolean(" ");               // true
Boolean([]);                // true
Boolean({});                // true
Boolean(-1);                // true
Boolean(Infinity);          // true
Boolean(function () {});    // true

A shorter way to write Boolean(value) is !!value: the first ! flips the value to a Boolean, and the second flips it back. To keep only the truthy items of an array, pass the function itself to Array filter(): list.filter(Boolean).

Comparing and Combining Booleans

=== checks the value and the type. == converts first, so 5 == "5" is true; prefer ===. && means and, || means or, and ! means not. && and || do not always return a Boolean: they return one of the two values you gave them, which is how name || "guest" picks a default.

JavaScript
5 > 3;                  // true
5 === "5";              // false (different types)
5 == "5";               // true (loose: converts first)
true && false;          // false
true || false;          // true
!true;                  // false
!!"text";               // true (double not is the same as Boolean(text))
"" || "guest";          // "guest" (|| gives the first truthy value)
"Asha" && "admin";      // "admin" (&& gives the last value when all are truthy)
0 && "never";           // 0 (&& stops at the first falsy value)

Booleans, Numbers, and Strings

In math, true counts as 1 and false as 0. When you join a Boolean with text, you get the words "true" or "false", which JavaScript makes with toString(). Going the other way needs care: the text "false" is truthy. Read text flags with text === "true", or parse JSON with JSON.parse().

JavaScript
true + 1;               // 2
false + 1;              // 1
true + true;            // 2
Number(true);           // 1
Number(false);          // 0
Number("true");         // NaN (the word is not a number)
String(true);           // "true"
true + "";              // "true"
true + "1";             // "true1"
JSON.parse("false");    // false

Number covers the other conversions in more detail.

Where Booleans Are Used

  • Flags, such as isLoggedIn, hasItems, or darkMode, that remember a yes-or-no answer.
  • Conditions in if, while, and ? :, which pick the next step.
  • Toggles, where flag = !flag flips a switch such as a menu or a theme.
  • Filters, where a function returns true to keep an item, as in Array filter().
  • Validation, where a check such as age >= 18 answers whether the data is acceptable.
JavaScript
const isLoggedIn = true;
const cart = [];
const hasItems = cart.length > 0;
isLoggedIn && hasItems;          // false (the cart is empty)
let darkMode = false;
darkMode = !darkMode;
darkMode;                        // true (toggled)
[0, 1, "", null, "a"].filter(Boolean).join(",");   // "1,a" (falsy items removed)

JavaScript Examples

Three short programs that run in Node.js and in any browser tab.

Example 1 — Test Values for Truthy and Falsy

Put ten different values in an array and test each one in an if-style check. The labels array only helps print readable names.

JavaScript
const values = [0, 1, "", "0", "false", null, undefined, NaN, [], {}];
const labels = ["0", "1", "empty string", '"0"', '"false"', "null", "undefined", "NaN", "[]", "{}"];

for (let i = 0; i < values.length; i++) {
  console.log(labels[i] + " -> " + (values[i] ? "truthy" : "falsy"));
}
Try It Yourself

How It Works

  1. One loop tests every value. The condition values[i] ? "truthy" : "falsy" converts each item to a Boolean first, with the same rules as if.
  2. Only the eight falsy values fail. The number 0, the empty string, null, undefined, and NaN are falsy. -0, 0n, and false would be too.
  3. Empty is not always falsy. The texts "0" and "false" are truthy because they are not empty. An empty array [] and an empty object {} are objects, and objects are always truthy.

Example 2 — Read a Flag That Was Saved as Text

Forms, URLs, and storage hand you strings. Convert them with Boolean() and see why that is wrong for the text "false".

JavaScript
const inputs = ["", "0", "false", "yes"];

for (let i = 0; i < inputs.length; i++) {
  console.log('"' + inputs[i] + '" -> ' + Boolean(inputs[i]));
}

const saved = "false";
console.log(Boolean(saved));        // true
console.log(saved === "true");      // false
console.log(!!saved);               // true
console.log(!saved);                // false
Try It Yourself

How It Works

  1. Strings follow the empty rule. Boolean(text) is false only for the empty string. "0", "false", and "yes" are all true.
  2. Compare to read the meaning. saved === "true" is true only for the exact text "true", so for "false" it gives the correct false.
  3. !! is Boolean() in short form. !!saved repeats the mistake: it is true. A single ! flips the Boolean, so !saved is false because the text is truthy.

Example 3 — Why new Boolean(false) Surprises You

Compare a plain false with a Boolean object that holds false. The object runs the if block, and the plain value does not.

JavaScript
const real = false;
const boxed = new Boolean(false);

console.log(typeof real);        // boolean
console.log(typeof boxed);       // object

if (boxed) {
  console.log("boxed runs");     // boxed runs
}
if (real) {
  console.log("real never prints");
}

console.log(boxed == false);     // true
console.log(boxed === false);    // false
console.log(boxed.valueOf());    // false
Try It Yourself

How It Works

  1. A primitive and an object. real is a primitive, so typeof gives boolean. new Boolean(false) is an object, so it gives object.
  2. Only the object runs the block. An if asks whether the value is truthy. An object always is, so boxed runs its block. The plain false does not.
  3. Equality shows the difference. == unwraps the object before comparing, so it says true. === compares types too, so it says false. valueOf() returns the plain false.

Boolean Method Groups

Boolean has only two methods. Each one has a full tutorial with examples you can run.

GroupMethodsUse them to
Convert a BooleantoString(), valueOf()show a Boolean as text for a label, a log line, or a URL, or unwrap a Boolean object into a plain true or false

Full list with one-line descriptions: Boolean Methods index.

Frequently Asked Questions

A Boolean is a primitive type with exactly two values, true and false. It answers yes-or-no questions and drives if statements. typeof true is "boolean".
false, 0, -0, 0n, "" (the empty string), null, undefined, and NaN. Every other value is truthy, including "false", "0", [], and {}.
Boolean("false") is true because it only checks whether the string is empty, not what it says. To read a saved flag, compare the text: str === "true". JSON.parse("false") also gives the real false.
Boolean(false) is the plain primitive false. new Boolean(false) is an object with typeof "object", and every object is truthy, so if (new Boolean(false)) runs its block. Call valueOf() to get the plain false out of it.
It converts any value to a Boolean. The first ! turns the value into the opposite Boolean, and the second ! turns it back, so !!"hello" is true and !!0 is false. It is the same as Boolean(value).

Browse every Boolean method

Open the index for toString() and valueOf(), plus a table of the Boolean features around them.

Boolean Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

16 people found this page helpful