This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

Boolean

Summary

Creates a new Boolean (true/false) value.

Syntax

new Boolean ([ boolValue ])

([ boolValue ])
boolValue
Required. The initial Boolean value for the new object. Possible values are true and false.

Other values (like 1 and 0) are converted to a Boolean expression.

Return Value

If the boolean value is omitted, or is false , 0, null , NaN , or an empty string, Boolean returns false. Otherwise, it returns true true.

Examples

Using Boolean to define a test condition

var x = new Boolean(false);
// This value can also be expressed as x = false;
if (x) {
  // . . . this code will not be executed
}

Using implicit Boolean constructor

// Implicit use of new Boolean(true)
var IsLoggedIn = true;
if (isLoggedIn) {
  // actions that are only done when isLoggedIn is true
}

Remarks

The Boolean object is a wrapper for the Boolean data type. JavaScript implicitly uses the Boolean object whenever a Boolean data type is converted to a Boolean object.

You rarely instantiate the Boolean object explicitly.

Properties

The following table lists the properties of the Boolean object.

PropertySummary
prototypeReturns a reference to the prototype for a Boolean.

Functions

The following table lists the functions of the Boolean object.

Methods

The following table lists the methods of the Boolean object.

MethodSummary
constructorInitializes a Boolean object.
toStringReturns a string representation of a Boolean object.

See also

Specification

Boolean Objects ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011

Attributions

  • Microsoft Developer Network: Article