Function boolean

Create a boolean or convert a string or number to a boolean. In case of a number, true is returned for non-zero numbers, and false in case of zero. Strings can be 'true' or 'false', or can contain a number. When value is a matrix, all elements will be converted to boolean.




Parameter Type Description
value string | number | boolean | Array | Matrix | null A value of any type


Type Description
boolean | Array | Matrix The boolean value


boolean(0);     // returns false
boolean(1);     // returns true
boolean(-3);     // returns true
boolean('true');     // returns true
boolean('false');     // returns false
boolean([1, 0, 1, 1]);     // returns [true, false, true, true]

See also

bignumber, complex, matrix, string, unit