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.
Examples:
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.
Examples:
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.
Examples:
var
variable1 = 11.11;
var variable2 = -11.11;
4. String. A string contains some characters.
Example:
var variable = "WMLScript Tutorial";
5. Invalid. This is used to indicate that a variable is invalid.
Example:
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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data