WMLScript Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 3 - Essential Language Elements
Section 16 out of 57 total sections , Section 3 out of 6 sections in this chapter


Literals

Literals are values that are hard-coded into your script. This section describes the following types of literals:



Integer Literals

Integer Literals are whole numbers expressed in one of the following ways:



Floating-Point Literals

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:



String Literals

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:

Some characters cannot be represented within string literals. WMLScript supports special escape sequences to represent these characters.

Character represented  Symbol  Sequence 

Apostrophe or single quote 

'  
\'  

Double quote 

"  
\"  

Backslash 

\  
\\  

Slash 

/  
\/  

Backspace 

 
\b  

Form feed 

 
\f  

Newline 

 
\n  

Carriage return 

 
\r  

Horizontal tab 

 
\t  

A character with the encoding specified by two hexadecimal digits hh (Latin-1 ISO8859-1) 

 
\xhh  

A character with the encoding specified by the three octal digits ooo (Latin-1 ISO8859-1) 

 
\ooo  

A Unicode character with the encoding specified by the four hexadecimal digits hhhh

 
\uhhhh  



Boolean Literals

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

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  
}  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKDS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.