11.6. WMLScript String Operators - Concatenating Strings

Preferences - Do not show ads

The + operator has two uses in WMLScript. One use is to calculate the addition result of two numbers. We have seen how to do this earlier. Another use is to concatenate two strings. If both operands are numeric values, the + operator will act as the addition operator; if any one of the operands is a string, the + operator will act as the string concatenation operator. For example:

x = 1 + 1;
y = 1 + "1";

After executing the above script, x has the integral value 2 and y has the string value "11".

Like the + operator, the += operator can also be used for both addition and string concatenation. The script below demonstrates its use:

var z = "WML Tutorial and ";
z += "WMLScript Tutorial";

After executing the above script, z contains the string "WML Tutorial and WMLScript Tutorial". The above script is equivalent to the one below:

var z = "WML Tutorial and ";
z = z + "WMLScript Tutorial";

Previous Page Page 23 of 71 Next Page

Contents at a Glance (Click Here for Full Table of Contents)
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?

WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page