7.1 The Assignment Operator (=)The assignment operator causes the operand on the left side of the operator to have its value changed to whatever is on the right side of the operator. The following expression assigns the value 15 to myVariable: myVariable = 15; The assignment operator also allows you to chain assignments, assigning the same value to multiple variables as follows: myOtherVariable = myVariable = 15; The previous statement assigns 15 to myVariable, and then also assigns the value (15) to myOtherVariable. This works because the statement: myVariable = 15; is an expression. It evaluates to the value assigned; that is, the expression: myVariable = 15; itself evaluates to 15, and it is this value (15) that is then assigned to myOtherVariable.
|