7.2. WMLScript Variable Naming Conventions

In WMLScript, the naming conventions of variables are the same as that of functions. Variable names are case-sensitive and they cannot be the same as WMLScript reserved words and keywords. The first character of a variable name has to be a letter or an underscore. The rest of the characters can be letters, numbers, or underscores.


7.3. Scope and Lifetime of WMLScript Variables

In WMLScript, after you have declared a variable in a function, you can modify or read the value of the variable until the function ends. The variable will be destroyed when the execution of the function is finished. Hence, the scope of a WMLScript variable is from the place where it is declared to the end of the function, and the lifetime of it starts from the time it is declared to the time when the function finishes. This means you can use the same variable name in different WMLScript functions, since the scope of a variable does not go outside the function where the variable is declared.

Note that block statements have no effect in variable scoping (a block statement is a group of statements that are enclosed within {}). For example, the following code is correct in WMLScript:


function wmlscript_func()
{
  {
     var wmlscript_variable;
  }
  {
     wmlscript_variable = "Welcome to our WMLScript tutorial";
  }
  wmlscript_variable = "WMLScript Tutorial";
}


Previous Page Page 12 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page