Name
Boolean( ) Global Function — convert a value to the boolean datatype
Availability
Flash 5
Synopsis
Boolean(value)
Arguments
- value
An expression containing the value to be converted to a Boolean.
Returns
The result of converting value to a
primitive Boolean (either true or
false).
Description
The Boolean( ) global function converts its
argument to a primitive Boolean value and returns that converted
value. The results of converting various types of data to a primitive
Boolean are described in Table 3.3. It’s
normally not necessary to use the Boolean( )
function; ActionScript automatically converts values to the
boolean type when appropriate.
Usage
Be sure not to confuse the global Boolean( )
function with the Boolean class constructor. The
Boolean( ) function converts its argument to the
boolean datatype, whereas the
Boolean class constructor creates a new Boolean
object. Note that in ECMA-262, all nonempty strings convert to
true. In Flash 5, only strings that can be
converted to a valid nonzero number convert to
true. Therefore, even the string
“true” converts to the Boolean false.
Example
var x = 1;
if (Boolean(x)) {
trace("x is true");
}See Also
The Boolean class; Section 3.4 in Chapter 3
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access