Boolean (Primitive value)

A built-in primitive value.

Availability:

ECMAScript edition - 2
Property/method value type:Boolean primitive

A Boolean value is a member of the Boolean type and may have one of two unique values, either true or false.

In some languages the values true and false also equate to numeric values. False is commonly 0 and true any non-zero value. In JavaScript this is not the case. The value false does not test equal against zero. However, a false Boolean value does become zero when converted to a number.

If you create a Boolean object and set it to the value true, you cannot convert it to a number with the toNumber() method, because this generates a runtime error. However, you can coerce the Boolean value into a numeric value by preceding it with a unary plus sign. So +true is a numeric primitive and yields the value 1, while false is converted to zero.

See also:false, JavaScript to Java values, true

Cross-references:

ECMA 262 edition 2 - section - 4.3.13

ECMA 262 edition 3 - section - 4.3.13

Wrox Instant JavaScript - page - 14