JavaScript: Boolean Constructor

By Xah Lee. Date: . Last updated: .
Boolean(arg)
Force arg to be the Primitive Value true or false, return it.
console.log(Boolean(0) === false);
console.log(Boolean(0.0) === false);
console.log(Boolean(0.) === false);
console.log(Boolean(.0) === false);

console.log(Boolean("") === false);

console.log(Boolean(null) === false);
console.log(Boolean(undefined) === false);
console.log(Boolean(NaN) === false);

// anything else is true
console.log(Boolean(1));
console.log(Boolean(-1));
console.log(Boolean(Infinity));
console.log(Boolean({}));
console.log(Boolean([]));
console.log(Boolean(function () {}));
// Boolean called as a function, returns true/false primitive value
console.log((typeof Boolean(3)) === "boolean");
new Boolean(arg)
Convert arg to a value that's a boolean object type, return it.
let xx = new Boolean(2);

console.log((typeof xx) === "object");
console.log(xx.valueOf() === true);

JavaScript Boolean

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Boolean

prototype