JavaScript Boolean valueOf() Method

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

Definition

valueOf() returns the primitive Boolean value, which is the plain true or false. A primitive is a simple value, not an object. Most Booleans in your code are already primitives, and true.valueOf() just returns true. The method matters for a wrapper object, which is an object that holds a value inside, made with new Boolean(value) or Object(value). A wrapper has typeof "object" and is truthy (it counts as true in an if) even when it holds false. Call valueOf() to unwrap it. This method takes no parameters.

Remember
const boxed = new Boolean(false);   // a Boolean wrapper object
typeof boxed;                         // "object"
typeof boxed.valueOf();               // "boolean"
boxed ? "truthy" : "falsy";           // "truthy" (every object is truthy)
boxed.valueOf() ? "truthy" : "falsy"; // "falsy"
boxed === false;                      // false (an object is not a primitive)
boxed.valueOf() === false;            // true
boxed + 1;                            // 1 (valueOf() is called automatically)

Syntax

Call it on a Boolean value or on a Boolean object. It takes no arguments.

JavaScript
boolean.valueOf()
CallWhat it does
true.valueOf()On a primitive it returns the same value, true. There is nothing to unwrap.
new Boolean(false).valueOf()Unwraps the object and returns the primitive false, with typeof "boolean".
Object(true).valueOf()Object(true) also makes a Boolean wrapper, and valueOf() gives the plain true back.
wrapper + 1You rarely call it yourself: math, +, and loose == call valueOf() for you. An if does not.
Boolean.prototype.valueOf.call("true")A string is not a Boolean or a Boolean object, so this throws a TypeError. Use Boolean(value) to convert instead.

Part of JavaScript since its first versions. Boolean.prototype is itself a Boolean object with the value false, so Boolean.prototype.valueOf() returns false. Wrapper objects are rare in modern code: the usual way to make one is the old-style new Boolean(value), and Boolean(value) without new gives a plain primitive.

Library declarations
JavaScript
boolean.valueOf()   // returns the primitive true or false

// Works on a Boolean primitive or a Boolean object.
// Anything else as "this" throws a TypeError.

Parameters

ParameterDescription
(none)valueOf() takes no parameters. Any argument you pass is ignored.

Return Value

Return ValueDescription
BooleanThe primitive true or false held by the object, so typeof the result is always "boolean". A primitive returns itself.

JavaScript Examples

Example 1 — A Boolean Object vs a Plain Boolean

Make a plain true and two wrapper objects that hold true. Check their types, then unwrap them with valueOf().

JavaScript
const plain = true;
const boxed = new Boolean(true);
const alsoBoxed = Object(true);

console.log(typeof plain);                  // boolean
console.log(typeof boxed);                  // object
console.log(boxed instanceof Boolean);      // true
console.log(plain instanceof Boolean);      // false
console.log(plain.valueOf());               // true
console.log(typeof alsoBoxed.valueOf());    // boolean
console.log(boxed.valueOf() === plain);     // true

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

How It Works

  1. Two kinds of true. plain is a primitive, so typeof says boolean. new Boolean(true) is an object, so typeof says object, and instanceof Boolean is true only for the object.
  2. valueOf() gives the primitive. On a primitive, valueOf() returns the same true. On Object(true) it returns the value inside, and boxed.valueOf() === plain compares two primitives, so it is true.
  3. A string cannot be unwrapped. .call("true") runs the method on a string, which holds no Boolean value, so JavaScript throws a TypeError.

Example 2 — Why if (new Boolean(false)) Still Runs

Every object is truthy, even a Boolean object that holds false. See what an if does before and after unwrapping.

JavaScript
const answer = new Boolean(false);

if (answer) {
  console.log("object: the if block runs");      // object: the if block runs
}

if (answer.valueOf()) {
  console.log("never printed");
} else {
  console.log("unwrapped: the else block runs"); // unwrapped: the else block runs
}

console.log(String(answer));                     // false
console.log(Boolean(answer));                    // true
console.log(Boolean(answer.valueOf()));          // false
Try It Yourself

How It Works

  1. An object counts as true. The first if only asks whether answer is truthy. An object always is, so the block runs even though the value inside is false.
  2. Unwrap, then test. answer.valueOf() is the primitive false, so the second if goes to its else block.
  3. The text can fool you. String(answer) prints false, but Boolean(answer) is still true. Only Boolean(answer.valueOf()) gives the false you wanted.

Example 3 — Unwrap Before You Compare, Add, or Store

Two wrappers that hold the same value are still two different objects. Unwrap them before comparing, counting, or putting them into a Set.

JavaScript
const a = new Boolean(true);
const b = new Boolean(true);

console.log(a === b);                       // false
console.log(a == b);                        // false
console.log(a.valueOf() === b.valueOf());   // true
console.log(a + 1);                         // 2
console.log(a + "x");                       // truex
console.log(new Set([a, b, true]).size);    // 3
console.log(new Set([a.valueOf(), b.valueOf(), true]).size);   // 1
Try It Yourself

How It Works

  1. Different objects are never equal. a === b and a == b compare two objects by identity, so both are false. After valueOf(), both sides are the primitive true, so the comparison is true.
  2. Operators unwrap for you. In a + 1 and a + "x", JavaScript calls valueOf() behind the scenes. true counts as 1, so you get 2, and joining with text gives truex.
  3. A Set needs plain values. A Set keeps one copy of each value but treats each object as unique, so a, b, and true make 3 items. The unwrapped values are all true, so the size is 1.

Browser & Runtime Support

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

✓ Baseline · Long-standing

Boolean.prototype.valueOf()

Works the same in all browsers and in every version of Node.js, Deno, and Bun. The rules for wrapper objects have not changed.

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.valueOf() Excellent

Bottom line: Safe to use everywhere. In everyday code you will seldom call it directly, because Boolean wrapper objects are rare and operators such as + unwrap them automatically.

Frequently Asked Questions

The primitive true or false. For a plain Boolean such as true it returns true itself. For a Boolean object made with new Boolean(false) it returns the false inside.
Because new Boolean(false) is an object, and every object is truthy. The if does not look at the value inside. Write if (box.valueOf()), or avoid new Boolean() completely.
No. Write the literal true or false, or Boolean(value) without new to convert something. The new version makes an object with typeof "object", which is truthy even for false and is never === to a plain Boolean.
Loose == converts the object with valueOf() first, so it compares false with false. Strict === never converts: an object is not a primitive, so the result is false.
No. Boolean.prototype.valueOf.call("true") throws a TypeError, because valueOf only unwraps Booleans. Use Boolean(value) or !!value to convert, and remember that Boolean("false") is true.

Back to the Boolean Method Index

See both Boolean methods side by side, with a one-line summary and the features that surround them.

Boolean methods →

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