JavaScript Boolean Reference

JavaScript Booleans

JavaScript booleans can have one of two values: true or false.

The Boolean() Function

You can use the Boolean() function to find out if an expression is true:


Boolean(10 > 9)       // returns true

Try it Yourself »

Or even easier:


(10 > 9)              // also returns true
10 > 9                // also returns true

Try it Yourself »

For a tutorial about booleans, read our JavaScript Boolean Tutorial.

Boolean Properties

Property Description
constructor Returns the function that created JavaScript’s Boolean prototype

The return value is a reference to the function, not the name of the function:

  • For JavaScript numbers the constructor property returns function Number() { [native code] }
  • For JavaScript strings the constructor property returns function String() { [native code] }
  • For JavaScript booleans the constructor property returns function Boolean() { [native code] }
prototype Allows you to add properties and methods to the Boolean prototype.

Boolean.prototype does not refer to a single boolean, but to the Boolean() object itself. Prototype is a global object constructor which is available for all JavaScript objects.

Boolean Methods

Method Description
toString() Converts a boolean value to a string, and returns the result. This method is called by JavaScript automatically whenever a boolean is used in a string operation.
valueOf() Returns the primitive value of a boolean. This method is usually called automatically by JavaScript behind the scenes, and not explicitly in code.