Skip to content

Boolean_Literals

Christoffer Fink edited this page Jul 16, 2014 · 6 revisions

The strings 'true' and 'false' are valid boolean literals. Numbers are also valid literals, and all of them are false. However, floating point numbers are only valid if they do not begin with a period. Invalid literals are allowed, but they are silently ignored.

Examples (valid)

  • 'true'
  • '0'
  • '-0.5'
  • '123456'

Examples (invalid)

  • 'True'
  • 'TRUE'
  • '.5'
  • 'hello'
  • '' (empty string)

Note

  • Boolean literals are case sensitive!
  • All valid numbers are false, even 1!

Suggestions for Future Versions

Literals should either be valid or they should not be valid. If they are not valid, then they should not be legal. They should at least generate a warning.

Literals should be case insensitive, and they should be valid if and only if they are sensible. Some or all of the following should be valid.

  • '1' and '0'
  • 'yes' and 'no'
  • 'on' and 'off'

Vague and non-intuitive notions should be avoided. For example, in contrast to JavaScript and C language rules, the length of the literal should be irrelevant, and non-zero values (other than 1) should not be true.

Tests

See Boolean Literals test for details.

Clone this wiki locally