8. WMLScript Data Types

Like JavaScript, WMLScript is weakly typed. WMLScript has only one type of variable, which is var. However, WMLScript variables are actually handled as five primitive data types internally. A variable can be used to store a value of any of the five primitive data types. The data types supported in WMLScript are:

1. Boolean. A Boolean value can be true or false.


var variable1 = true;
var variable2 = false;

2. Integer. WMLScript uses 32-bit integers with two's complement. This means an integer value can be in the range from -232/2 to 232/2-1, i.e. -2147483648 to 2147483647.


var variable1 = 10000;
var variable2 = -10000;

3. Float. WMLScript uses 32-bit single precision format to represent floating-point numbers. The maximum value supported is 3.40282347E+38. The smallest positive nonzero value supported is 1.17549435E-38. Note that some mobile devices do not support floating-point numbers. The float() function of WMLScript's Lang standard library can be used to check whether a mobile device supports floating-point numbers.


var variable1 = 11.11;
var variable2 = -11.11;

4. String. A string contains some characters.


var variable = "WMLScript Tutorial";

5. Invalid. This is used to indicate that a variable is invalid.


var variable = invalid;

Sometimes the result of an operation is of the invalid type. This means errors have occurred during the operation. One example is the divide-by-zero error:

var variable = 100 / 0;

After the execution of the above script, variable contains the invalid value. You can use the isvalid operator to find out whether a variable is of the invalid data type. It will be covered shortly in this WMLScript tutorial.

The data types of operands determine the action of an operator. For example, + is both the addition operator and the string concatenation operator. If the operands of the + operator are numeric values, the addition operation will be done. For example, the result of 10+15 is 25. If any operands of the + operator are of the string data type, the string concatenation operation will be done. For example, the result of "10"+"15" is "1015". The WMLScript interpreter will carry out a data type conversion automatically if necessary. For example, if the WMLScript interpreter encounters the operation 10+"15", the numeric value 10 will first be converted to the string data type. After that the string concatenation operation will be performed. The result will be "1015".

Previous Page Page 13 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.