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 |
ECMA 262 edition 2 - section - 4.3.13
ECMA 262 edition 3 - section - 4.3.13
Wrox Instant JavaScript - page - 14
Prev | Home | Next |
Bookmarklets | Up | boolean |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |