Parameter | Type | Description |
---|---|---|
INPUT | VALUE | The input value (any type). |
VALUE(BOOLEAN) | The boolean value of the input value. |
This function returns the boolean value of the input value or expression. TRUE is returned for values that are true-equivalent, and FALSE is returned for false-equivalent values. In general, zero values, NaN, and zero-length strings are considered to be FALSE, and everything else is TRUE. Lists, no matter their contents or amount of elements, are TRUE.
If the input value is already a boolean, it is returned as-is. This function does not change or convert a value in-place - you must reassign the result.
In multiple places in this documentation, you'll see the phrase "true-equivalent," which means "a value that would evaluate as TRUE if converted to boolean." This is important for all logical operations and control branches.
The type of each of the values are most visible in a trace.
world
{
start()
{
textln("asBoolean(true) = "+asBoolean(true));
textln("asBoolean(false) = "+asBoolean(false));
textln("asBoolean(0) = "+asBoolean(0));
textln("asBoolean(5) = "+asBoolean(5));
textln("asBoolean(\"\") = "+asBoolean(""));
textln("asBoolean(\" \") = "+asBoolean(" "));
textln("asBoolean(\"false\") = "+asBoolean("false"));
textln("asBoolean(5 + 3) = "+asBoolean(5 + 3));
textln("asBoolean(5 - 5) = "+asBoolean(5 - 5));
local a = 10;
textln("asBoolean(a) = "+asBoolean(a));
textln("a = "+a);
quit;
}
}
Value | Result | |
---|---|---|
BOOLEAN[false] | > BOOLEAN > | BOOLEAN[false] |
BOOLEAN[true] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[Infinity] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[-Infinity] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[NaN] | > BOOLEAN > | BOOLEAN[false] |
INTEGER[0] | > BOOLEAN > | BOOLEAN[false] |
FLOAT[0.0] | > BOOLEAN > | BOOLEAN[false] |
INTEGER[10] | > BOOLEAN > | BOOLEAN[true] |
INTEGER[3] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[10.0] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[3.0] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[10.5] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[3.5] | > BOOLEAN > | BOOLEAN[true] |
INTEGER[-10] | > BOOLEAN > | BOOLEAN[true] |
INTEGER[-3] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[-10.0] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[-3.0] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[-10.5] | > BOOLEAN > | BOOLEAN[true] |
FLOAT[-3.5] | > BOOLEAN > | BOOLEAN[true] |
STRING[] | > BOOLEAN > | BOOLEAN[false] |
STRING[ ] | > BOOLEAN > | BOOLEAN[true] |
STRING[0] | > BOOLEAN > | BOOLEAN[true] |
STRING[0.0] | > BOOLEAN > | BOOLEAN[true] |
STRING[10] | > BOOLEAN > | BOOLEAN[true] |
STRING[3] | > BOOLEAN > | BOOLEAN[true] |
STRING[10.0] | > BOOLEAN > | BOOLEAN[true] |
STRING[3.0] | > BOOLEAN > | BOOLEAN[true] |
STRING[10.5] | > BOOLEAN > | BOOLEAN[true] |
STRING[3.5] | > BOOLEAN > | BOOLEAN[true] |
STRING[-10] | > BOOLEAN > | BOOLEAN[true] |
STRING[-3] | > BOOLEAN > | BOOLEAN[true] |
STRING[-10.0] | > BOOLEAN > | BOOLEAN[true] |
STRING[-3.0] | > BOOLEAN > | BOOLEAN[true] |
STRING[-10.5] | > BOOLEAN > | BOOLEAN[true] |
STRING[-3.5] | > BOOLEAN > | BOOLEAN[true] |
STRING[apple] | > BOOLEAN > | BOOLEAN[true] |
STRING[banana] | > BOOLEAN > | BOOLEAN[true] |
STRING[NaN] | > BOOLEAN > | BOOLEAN[true] |
STRING[infinity] | > BOOLEAN > | BOOLEAN[true] |
LIST[[]] | > BOOLEAN > | BOOLEAN[true] |
LIST[[BOOLEAN[true], INTEGER[3], FLOAT[5.0], STRING[orange]]] | > BOOLEAN > | BOOLEAN[true] |