Boolean, Number and String

The Boolean type has only two values. The constants for these values are

true
and
false
and are only used for truth values. Unlike some languages,
false
isn't exactly the same as
0
(zero), but it will convert to 0 when used where a number is expected, so it's much the same thing.

The Number type is for floating point numbers with zero or more decimal places There is no separate type for plain whole numbers, integers or bytes. Number constants can be written plainly in decimal, or in computer exponential or hexadecimal or octal notation. All these formats are shown in the above example. The Number type can cope with very large (or very small) values and negatives. Very large means up to about 10308, very small means down to about 10-308, if you're mathematically inclined.

The String type is for textual characters. There is no type for representing just one character. A String is a row of zero or more characters as a unit, not an array of single characters. Of course, a String of exactly one character is as good as a single character, so that is the way a single character is represented. There are a few special characters which can be stored in a String, all of which begin with a '

\
' The '
\n
' in '
Hello, World!\n
' above is an example—it adds a newline character to the string. Strings must start and end with single quotes, or with double quotes. You should be careful when putting quotes intentionally inside Strings, and the start and end quotes must match in type.

© 1997 by Wrox Press. All rights reserved.