OPERATORS:  +


+
 
The + plus string operator is used to concatenate (join together) two or more strings. This example 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-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information