Javascript Reference
Categories: Operators

javascript Operators +

@March 15, 2008, 1:22 a.m.
+ Firefox/Netscape/NN 2 IE 3 ECMA 1  

  

The addition operator works with both numbers and strings, but its results vary with the data types of its operands. When both operands are numbers, the result is the sum of the two numbers; when both operands are strings, the result is a concatenation of the two strings (in the order of the operands); when one operand is a number and the other a string, the number data type is converted to a string, and the two strings are concatenated. To convert a string operand to a number, use the parseInt( ) or parseFloat( ) function.

 
Example
 
var mySum = number1 + number2;
var newString = "string1" + "string2";

Powered by Linode.