OPERATORS:  +

String operators are used to concatenate two strings.

+

The plus sign is used as a concatenation operator to produce a string that is one string attached to another. This example simply joins together the three strings 'bread', 'and' and 'cheese' to produce 'bread and cheese':

document.write("bread " + "and " + "cheese");

...while the next one would, assuming 'x' to contain the string 'honey', return 'milk and honey':

document.write("milk and " + x);

The shorthand assignment operator can also be used to concatenate strings. If the variable 'x' has the value 'milk and ', then the following code will add the string 'honey' to the value in variable 'x' producing the new string 'milk and honey':

Code:
var x = 'milk and ';
x += "honey";
document.write(x);

Output:
milk and honey

Copyright 1999 by Infinite Software Solutions, Inc.
Trademark Information