WMLScript Reference

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

Current chapter: Chapter 3 - Variables and Data Types
Section 13 out of 34 total sections , Section 2 out of 3 sections in this chapter


Variables

Variables are symbolic names for values coded in your script. You use variables to store and manipulate program data.

NOTE   WMLScript 1.1 supports only variables that are declared inside functions or passed as function parameters.

This section describes the following information about variables:



Declaration


Definition

Specifying the variable's name.


Examples

Examples of variable declarations are:

var x;  
var x, y;  
var size = 3;  

Comments

Use the var keyword to declare a variable. If you declare more than one variable in the same statement, separate the variables by a comma. End the variable declaration with a semi-colon (;).

WMLScript 1.1 requires you to declare variables. You must also declare a variable before you can use it. You do not have to initialize variables; if you do not, they are automatically initialized to contain an empty string ("").



Scope and Lifetime


Definition

A variable's scope is the segment of the program in which the variable can be referenced. A variable's lifetime is the time between the variable declaration and the end of the function. Lifetime is also known as persistence.


Comments

Variable names within a function must be unique. Block statements are not used for scoping.



Access


Definition

A variable is accessible only within the function in which it has been declared.


Examples

var   myAge   = 46  
var   yourAge = 60  
var   ourAge  = myAge + yourAge  

Comments

You access a variable by calling the variable's name. In the example above, the variable ourAge accesses the variables myAge and yourAge.


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


Part Number DKWS-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.