User Guide
32 Chapter 1: ActionScript Basics
Operator precedence and associativity
When two or more operators are used in the same statement, some operators take precedence over
others. ActionScript follows a precise hierarchy to determine which operators to execute first. For
example, multiplication is always performed before addition; however, items in parentheses [()]
take precedence over multiplication. So, without parentheses, ActionScript performs the
multiplication in the following example first:
total = 2 + 4 * 3;
The result is 14.
But when parentheses surround the addition operation, ActionScript performs the addition first:
total = (2 + 4) * 3;
The result is 18.
When two or more operators share the same precedence, their associativity determines the order
in which they are performed. Associativity can be either left-to-right or right-to-left. For example,
the multiplication (*) operator has an associativity of left-to-right; therefore, the following two
statements are equivalent:
total = 2 * 3 * 4;
total = (2 * 3) * 4;
The following table lists all the ActionScript operators and their associativity, from highest to
lowest precedence.
Operator Description Associativity
Highest precedence
x++
Post-increment Left to right
x--
Post-decrement Left to right
.
Object property access Left to right
[ ]
Array element Left to right
( )
Parentheses Left to right
function ( )
Function call Left to right
++x
Pre-increment Right to left
--x
Pre-decrement Right to left
-
Unary negation, such as x = -1 Left to right
~
Bitwise NOT Right to left
!
Logical NOT Right to left
new
Allocate object Right to left
delete
Deallocate object Right to left
typeof
Type of object Right to left
void
Returns undefined value Right to left