Data types define the type of data a variable can hold. WMLScript is a weakly-typed language that supports data types internally only. As a result, you do not have to specify the variable type and any variable can contain any type of data at any given time. WMLScript automatically converts between the various data types as needed.
Examples of data types include:
var flag = true; //Boolean
var number = 12; //integer
var temperature = 37.7; //floating-point
var number = "XII"; //string
var except = invalid; //invalid
In addition to the four standard data types, WMLScript uses a fifth data type, invalid, when a data type needs to be differentiated from the other internal data types.
This section describes the limitations and uses of the following WMLScript data types:
WMLScript supports integer values in the range -2147483648 to 2147483647. You can use Lang library functions to retrieve these values at run time:
Lang.maxInt (); //Maximum integer value
Lang.minInt (); //Minimum integer value
WMLScript supports a maximum floating-point value of 3.40282347E+38. The minimum positive nonzero value (at least the normalized precision must be supported) is 1.17549435E-38 or smaller.
WMLScript handles the special floating-point number types using the following rules:
If an operation results in a floating-point number that is not part of the set of finite real numbers (not a number, positive infinity, etc.), supported by the single-precision floating-point format, the result is invalid.
If an operation results in a floating-point underflow, the result is zero (0.0).
Negative zero and positive zero are equal and indistinguishable.
You can use the Float library functions to get the maximum and minimum values at run time:
Float.maxFloat (); //Maximum floating-point value supported
Float.minFloat (); //Minimum floating-point value supported
String variables are temporary combinations of letters, digits, or special characters. You can use string literals to initialize string variables. You can manipulate string values with the WMLScript operators and the functions specified in the standard String library.
Examples of String variables include:
var msg = "Hello";
var len = String.length(msg);
msg = msg + " Worlds!";
You can use Boolean values to initialize or assign a value to a variable and in statements that require a Boolean value as one of the parameters. Boolean values can be a literal or the result of a logical expression evaluation.
Examples of Boolean variables include:
var truth = true;
var lie = !true;