Chapter 10. WMLScript Datatypes, Variables, and Conversions

WMLScript is a weakly typed language. This means you never specify the datatype of a variable or the return type of a function. All expressions have a type internally, but WMLScript itself converts values back and forth between the different types as required, so that you don’t have to.

For example, the value 1234 is an integer, but if you pass it to the String.length( ) library function, which expects a string, it’s implicitly converted to the string "1234", the length of which is 4.

Similarly, if you try to evaluate the expression:

"1234" * "2"

both values are converted to integers before use, and the result is the integer 2468. This is what is meant by weak typing.

Datatypes and Literals

WMLScript has five datatypes: string, integer, floating-point number, Boolean, and the special type invalid. Every value in WMLScript belongs to one of these types, although most can be converted to others. The format of a literal value determines its type. (A literal is a constant included explicitly in the code.)

Strings

Strings in WMLScript can be any sequence of Unicode characters. They may be enclosed within either single or double quotes. The type of quotes used makes no difference to the string itself.

WMLScript supports special escape sequences to include special characters in strings. This can be used for nonprinting characters (such as newlines), characters that have a special meaning in strings (such as quotes), and characters ...

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.