toBoolean

Description

Tries to convert value to a boolean, according to these rules:

  1. If value is a number, 0 is false and anything else is true .

  2. 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.

  3. 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.

Syntax

toBoolean( value, [failover] )

Examples
 toBoolean(1) //returns true
 toBoolean("abc", false) //returns false