Assignment Operators

Top  Previous  Next

Operators:  =  *=  /=  %=  +=  -=  <<=  >>=  >>>=  &=  ^=  |=


l-value = expression

l-value op= expression


The = operator performs simple assignment. The value of expression is stored in l-value as a side effect. An l-value is a variable, array element, or property of an object. The result of the operator is the value assigned.


The other operators perform compound assignment. The operation:


 l-value op= expression


is equivalent to:


 l-value = l-value op expression


except that l-value is only evaluated once.


The assignment operators have right-to-left associativity. For example:


 x = y = expression


is evaluated as:


 x = (y = expression)


which therefore assigns the value of expression to both x and y.