Javascript Reference
Categories: Operators

javascript Operators +=

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

  

This is the add-by-value operator. This class of operator combines a regular assignment operator (=) with one of the many other operators to carry out the assignment by performing the stated operation on the left operand with the value of the right operand. For example, if a variable named a has a string stored in it, you can append a string to a with the += operator:

a += " and some more.";
 

Without the add-by-value operator, the operation had to be structured as follows:

a = a + " and some more";
 

The following table shows all the assignment operators that function this way.

 
Operator Example Equivalent
+= a += b a = a + b
-= a -= b a = a - b
*= a *= b a = a * b
/= a /= b a = a / b
%= a %= b a = a % b
<<= a <<= b a = a << b
>>= a >>= b a = a >> b
>>>= a >>>= b a = a >>> b
&= a &= b a = a & b
|= a |= b a = a | b
^= a ^= b a = a ^ b
 
Example
 
output += "<H1>Section 2</H1>";
		total *= .95;

Powered by Linode.