bool
bool* ( expression : any ) : boolean
Parameter | Type | Description | |
---|---|---|---|
expression | any | → | Expression for which to return the boolean form |
Result | boolean | ← | Boolean form of the expression |
Description
The bool
command returns the boolean form of the expression you passed in expression.
The command can return the following values, depending on the expression result type:
Expression result type | Return of the bool command |
---|---|
undefined | false |
null | false |
boolean | false if false, otherwise true |
number | false if 0, other true |
other types | false |
This command is useful when the code expects a boolean value, and when the evaluation of the expression could result in a different type (e.g. if it evaluates to null or undefined).
Examples
var result : boolean
result = bool(1) //true
result = bool(0) //false
result = bool("hello") //false
var o : object
o = {test: 42}
result = bool(o.test) //true
result = bool(o.otherTest) //false