toBoolean
Tries to convert value to a boolean, according to these rules:
-
If value is a number, 0 is false and anything else is true .
-
If value is a string, then the strings (case insensitive) "on", "true", "t", "yes", "y" are all true . The strings (case insensitive) "off", "false", "f", "no", "n" are considered false . If the string represents a number, the first rule applies. All other strings fail type casting.
-
All other types fail type casting.
If type casting fails, an error is thrown, unless the failover argument is specified, in which case it will be used.
toBoolean( value, [failover] )
toBoolean(
1
)
//returns true
toBoolean(
"abc"
,
false
)
//returns false