User Guide

Operators 79
For example, consider the less-than (<) and greater-than (>) operators, which have the same
precedence. If both operators are used in the same expression, the operator on the left is
processed first because both operators are left-associative. This means that the following two
statements produce the same output:
trace(3 > 2 < 1); // false
trace((3 > 2) < 1); // false
The greater-than operator is processed first, which results in a value of true because the
operand 3 is greater than the operand 2. The value
true is then passed to the less-than
operator, along with the operand 1. The following code represents this intermediate state:
trace((true) < 1);
The less-than operator converts the value true to the numeric value 1 and compares that
numeric value to the second operand 1 to return the value
false (the value 1 is not less than
1).
trace(1 < 1); // false
You can alter the default left associativity with the parentheses (()) operator. You can instruct
the compiler to process the less-than operator first by enclosing that operator and its operands
in parentheses. The following example uses the parentheses operator to produce a different
output using the same numbers as the previous example:
trace(3 > (2 < 1)); // true
The less-than operator is processed first, which results in a value of false because the operand
2 is not less than the operand 1. The value
false is then passed to the greater-than operator,
along with the operand 3. The following code represents this intermediate state:
trace(3 > (false));
The greater-than operator converts the value false to the numeric value 0 and compares that
numeric value to the other operand 3 to return
true (the value 3 is greater than 0).
trace(3 > 0); // true
The following table lists the operators for ActionScript 3.0 in order of decreasing precedence.
Each row of the table contains operators of the same precedence. Each row of operators has
higher precedence than the row appearing below it in the table.
Group Operators
Primary
[] {x:y} () f(x) new x.y x[y] <></> @ :: ..
Postfix
x++ x--
Unary
++x --x + - ~ ! delete typeof void
Multiplicative
* / %