Boolean Values

Boolean data has one of only two values:

  • true
  • false

Some operators and primitives return Boolean values. For example, the statement 1==2 returns false. Boolean values are used in control structures, such as the if statement.

All primitives requiring a Boolean value as an input accept a numeric or text value. The number zero is converted to the Boolean value false and all other numbers are converted to true. In addition, all text strings other than the empty string are converted to true.

Each of the following data items is converted to true when evaluated as a Boolean value:

true
1
2.3
"text"

Similarly, each of the following items is converted to false:

false
0
""
null

All primitives requiring a number as an input accept a Boolean value as well. The value true is converted to one and false is converted to zero. For example, the statement true+1 returns 2.