JavaScript Boolean toString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

toString() turns a Boolean into text. A Boolean is a value with only two choices, true or false. The result is the string "true" or the string "false", always in lowercase. The Boolean itself is a primitive, which means a plain value such as true, 42, or "hi" and not an object. Unlike Number’s toString(), this method has no parameters: there is no radix, because there is only one way to write a Boolean as text. The text is useful for labels, logs, URLs, and CSV files. It is not a Boolean any more, so the text "false" is truthy.

Remember
true.toString();                  // "true"
(false).toString();               // "false"
true.toString(2);                 // "true" (the argument is ignored)
new Boolean(false).toString();    // "false"
String(true);                     // "true"
Boolean("false");                 // true (the text "false" is truthy!)
"false" === "true";               // false (compare text like this)
Boolean.prototype.toString.call("true");   // TypeError

Syntax

Call it on a Boolean value, in parentheses or right after a literal. It takes no arguments.

JavaScript
boolean.toString()
CallWhat it does
true.toString()Gives the text "true". Writing a dot right after true or false is fine, because a Boolean literal has no decimal point.
isActive.toString()Gives "true" or "false" depending on the variable. It throws a TypeError if the variable holds null or undefined.
new Boolean(false).toString()A Boolean object gives the text of the value inside it: "false", even though the object itself is truthy.
true.toString(2)Still gives "true". A radix works for numbers, but Boolean ignores any argument you pass.
String(isActive)The same text, and safe for null and undefined: String(null) is "null" instead of an error.

Part of JavaScript since its first versions. JavaScript calls toString() for you when a Boolean meets a string: "on: " + true, a template literal, and [true, false].join() all give the text. Boolean.prototype is itself a Boolean object whose value is false, so Boolean.prototype.toString() returns "false".

Library declarations
JavaScript
boolean.toString()   // returns "true" or "false"

// No parameters: extra arguments are ignored.
// "this" must be a Boolean or a Boolean object,
// anything else throws a TypeError.

Parameters

ParameterDescription
(none)toString() takes no parameters. Any argument is ignored, so true.toString(2) and true.toString(16) both return "true". This is different from Number.prototype.toString(radix).

Return Value

Return ValueDescription
StringExactly "true" or "false", in lowercase. It is never "True", "1", or "yes". To go back to a Boolean, write text === "true".

JavaScript Examples

Example 1 — Turn a Flag Into a Status Label

A flag is a Boolean variable such as isActive. Its text can be used as a key to look up a friendly label. The extra argument in the last line is ignored.

JavaScript
const labels = { true: "Active", false: "Inactive" };
const isActive = true;

const key = isActive.toString();
console.log(key);                           // true
console.log(typeof key);                    // string
console.log(key.length);                    // 4
console.log(labels[key]);                   // Active
console.log(labels[(3 > 5).toString()]);    // Inactive
console.log(isActive.toString(2));          // true
Try It Yourself

How It Works

  1. The flag becomes a string. isActive.toString() gives "true". The first typeof check proves the result is a string, and "true" has 4 characters.
  2. The text is the lookup key. Object keys are text, so labels["true"] finds "Active". A comparison such as 3 > 5 gives false, and its text "false" finds "Inactive".
  3. The radix is ignored. toString(2) would give binary digits for a number. A Boolean has no digits to change, so the argument is ignored and the answer is still "true".

Example 2 — Build a Query String and a List of Flags

URLs, CSV files, and logs need text, not Booleans. Join the flags into a query string, print a list, and see why String() is the safe choice for missing values.

JavaScript
const filters = { active: true, admin: false };
const parts = [];
for (const key in filters) {
  parts.push(key + "=" + filters[key].toString());
}
console.log("?" + parts.join("&"));    // ?active=true&admin=false

const flags = [true, false, true];
console.log(flags.join(","));          // true,false,true
console.log(flags.map(function (f) { return ["no", "yes"][Number(f)]; }).join(" "));   // yes no yes

const missing = null;
console.log(String(missing));          // null
try {
  missing.toString();
} catch (e) {
  console.log(e.name);                 // TypeError
}
Try It Yourself

How It Works

  1. Each flag becomes key=text. The loop turns true and false into "true" and "false" and joins the pairs with &, which is the format of a URL query string.
  2. Lists are joined with text too. join(",") calls toString() on every item behind the scenes. For friendlier words, Number(true) is 1 and Number(false) is 0, so ["no", "yes"][Number(f)] picks the right word.
  3. String() does not crash. String(null) is the text "null". Calling .toString() on null has nothing to run on, so it throws a TypeError.

Example 3 — Read a Boolean Back From Text

Saved settings often come back as strings. This example shows why Boolean("false") is wrong and what to write instead.

JavaScript
const saved = (false).toString();
console.log(saved);                  // false
console.log(typeof saved);           // string
console.log(Boolean(saved));         // true
console.log(saved === "true");       // false
console.log(JSON.parse(saved));      // false

try {
  Boolean.prototype.toString.call("true");
} catch (e) {
  console.log(e.name);               // TypeError
}
Try It Yourself

How It Works

  1. The saved value is text. (false).toString() gives "false", a string with five letters. It looks like a Boolean when printed, but typeof says string.
  2. Any non-empty string is truthy. Boolean(saved) is true, so an if on this text would run. Comparing with === "true" gives the correct false, and JSON.parse("false") also gives a real false.
  3. The method only accepts Booleans. .call("true") runs the method on a string. A string is not a Boolean or a Boolean object, so JavaScript throws a TypeError.

Browser & Runtime Support

Boolean.prototype.toString() has been part of JavaScript since the first language versions, so every browser and runtime has it.

✓ Baseline · Long-standing

Boolean.prototype.toString()

Works the same in all browsers and in every version of Node.js, Deno, and Bun. The result is always the lowercase text true or false.

100% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium
Full support
Opera All versions
Full support
Samsung Internet All versions · Android
Full support
Internet Explorer All versions
Full support
Node.js All versions · checked on Node 24
Supported
Deno All releases
Supported
Bun All releases
Supported
Boolean.prototype.toString() Excellent

Bottom line: Use it freely anywhere. Only the wording of the TypeError messages (for a missing value or a wrong this) differs between engines, so check e.name instead of the message.

Frequently Asked Questions

Call flag.toString() or String(flag). Both give "true" or "false". Template literals and joining with a string do the same. When the flag sits inside an object, JSON.stringify() also writes it as true or false.
No. A Boolean has no digits to change, so the argument is ignored: true.toString(2) is still "true". Only Number and BigInt use a radix.
Because "false" is a non-empty string, and every non-empty string is truthy. To read a saved flag, compare it: text === "true". For JSON text, JSON.parse("false") gives the real false.
null and undefined have no methods, so calling .toString() on them throws a TypeError. String(value) works for any value and gives "null" or "undefined" instead.
It returns "false". Boolean.prototype is itself a Boolean object whose value is false, so the method works on it. This is a curiosity: in real code you call toString() on your own values.

Next: valueOf()

Learn how to get the plain true or false out of a Boolean object, and why an object made with new Boolean(false) is truthy.

valueOf() tutorial →

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.

11 people found this page helpful