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()
Call
What 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 + 1
You 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
Parameter
Description
(none)
valueOf() takes no parameters. Any argument you pass is ignored.
Return Value
Return Value
Description
Boolean
The 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().
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.
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.
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
object: the if block runs
unwrapped: the else block runs
false
true
false
How It Works
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.
Unwrap, then test.answer.valueOf() is the primitive false, so the second if goes to its else block.
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.
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.
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.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium
Full support
OperaAll versions
Full support
Samsung InternetAll versions · Android
Full support
Internet ExplorerAll versions
Full support
Node.jsAll versions · checked on Node 24
Supported
DenoAll releases
Supported
BunAll 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.