Literals are values that are hard-coded into your script. This section describes the following types of literals:
Integer Literals are whole numbers expressed in one of the following ways:
Decimal (base 10)
A decimal integer literal is a series of digits that does not begin with zero. Decimal integer literals contain only numbers.
Example: -41
Hexadecimal (base 16)
A hexadecimal integer literal is a series of digits that begins with 0X or 0x. Hexadecimal integer literals contain the numbers 0-9 and/or the letters a-f or A-F.
Example: 0xF3
Octal (base 8)
An octal integer literal begins with zero. Octal integer literals contain only the numbers 0-7.
Example: 032
Floating-point Literals are numbers that contain decimal places. Floating-point literals can contain decimals, fractions, or exponents. A floating-point literal must have at least one digit and either a decimal point or an exponent.
The exponent is an e or E followed by an integer. The exponent describes the number's base 10 logarithmic value. For example, e0 is comparable to 100; e-2 is comparable to 10-2. The exponent can be signed (preceded by + or -, denoting positive or negative).
A floating-point literal that is not within the specified value range produces a compiler error. A floating-point literal underflow results in a floating-point literal of zero (0.0).
The WMLScript compiler recognizes all of the following examples as the value 3.14:
3.14
3.14e0
.314E1
314e-2
A String Literal is any sequence of zero or more characters enclosed within double quotes ("") or single quotes ('').
String literals are pointers to a dynamic memory location that contains the character sequence. The application can alter the value of a string literal. WMLScript allows string literals to be enclosed by either single or double quotes, as long as you use the same type for a given literal. Beginning a string with a single quote and ending it with a double quote, for example, generates a compiler error.
Examples of string literals include all of the following:
'Dewey Defeats Truman!'
"Tuesday, October 5, 1999"
"15% off retail"
Some characters cannot be represented within string literals. WMLScript supports special escape sequences to represent these characters.
Boolean Literals are variables that store values of true or false. See the Appendix of the WMLScript Reference for more information about how WMLScript converts and promotes Boolean values.
Invalid Literals are variables that denote invalid values. The return type from any Invalid Literal is Invalid, as shown in the following example:
var x = 8;
var y = 0;
if ((x/y) == invalid) {
//display error message
}