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:
Boolean. A Boolean value can be true or false.
variable1 = true;
var variable2 = false;
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.
variable1 = 10000;
var variable2 = -10000;
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.
variable1 = 11.11;
var variable2 = -11.11;
String. A string contains some characters.
variable = "WMLScript Tutorial";
Invalid. This is used to indicate that a variable is invalid.
variable = invalid;
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
variable = 100 / 0;
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.
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".
Feedback Form (ExpandCollapse