O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required