WMLScript Developer's Guide

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

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


Variables

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

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

This section describes the following characteristics of variables:



Declaration

A Declaration specifies the name of a variable. WMLScript requires you to declare variables. You must also declare a variable before you can use it. You need not initialize variables, however; if you do not, they are automatically initialized to contain an empty string ("").

All variable declarations must be preceded by the var keyword. If you declare more than one variable in the same statement, separate the variables with a comma. End each variable declaration with a semi-colon (;). It is not necessary to declare the type of data a variable can hold.

Examples of variable declarations include:



Scope and Lifetime

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.

The scope of any variable is the function in which it is declared. Variable names within any function must therefore be unique. The scope of a variable cannot be limited to block statements within a function.



Access

A variable is accessible only within the function in which it is declared. You access a variable by calling the variable's name. In the example below, the variable ourAge accesses the variables myAge and yourAge.

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

[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.