
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Assignment Operator
|
115
In contrast, the = (assignment) operator is right-associative, so the expression:
a = b = c = d
says, “assign d to c, then assign c to b, then assign b to a,” as in:
a = (b = (c = d))
Operator associativity is fairly intuitive, but if you’re getting an unexpected value
from a complex expression, consult Table 5-1 or add extra parentheses. We’ll note
cases in which associativity is a common source of errors throughout the remainder
of this chapter.
Datatypes and Operators
Some operators accept varying datatypes as operands. Depending on the datatype of
an operand, the effect of an operator may change. The
+ operator, for example, per-
forms addition when used with numeric operands, but it performs concatenation
when used with string operands. If operands are of different datatypes or of the
wrong type, ActionScript will perform type conversion according to the rules
described in Chapter 3, which can have serious effects on your code.
The remainder of this chapter offers reference-style descriptions of each ActionScript
operator. Newer programmers may wish to skim past topics that have not yet been
covered in detail.
The Assignment Operator
We’ve already used the assignment operator frequently. It can place a value into a
variable, array element, or object property. ...