Skip to main content

bool

bool ( expression : any ) : boolean

ParameterTypeDescription
expressionany->Expression for which to return the boolean form
Resultboolean<-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 typeReturn of the bool command
undefinedfalse
nullfalse
booleanfalse if false, otherwise true
numberfalse if 0, other true
other typesfalse

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

See also

date
num
string
time