ActionScript 1.0 has the operators of ECMA-262, less a few, plus the word operators of Flash 4, which Flash 5 keeps so that old movies compile. How each one converts its operands is on Data types.
Precedence and associativity
Operators higher in the table bind more tightly. Operators on one row have the same
precedence and are grouped by their associativity: a - b - c is
(a - b) - c, and a = b = c is a = (b = c).
| Level | Operators | Kind | Associativity |
|---|---|---|---|
| 1 | x() x[] x.y x++ x-- | call, member, postfix | left to right |
| 2 | ++x --x +x -x ~ ! not new delete typeof void | unary | right to left |
| 3 | * / % | multiplicative | left to right |
| 4 | + - add | additive | left to right |
| 5 | << >> >>> | shift | left to right |
| 6 | < <= > >= instanceof lt le gt ge | relational | left to right |
| 7 | == != === !== eq ne <> | equality | left to right |
| 8 | & | bitwise and | left to right |
| 9 | ^ | bitwise exclusive or | left to right |
| 10 | | | bitwise or | left to right |
| 11 | && and | logical and | left to right |
| 12 | || or | logical or | left to right |
| 13 | ?: | conditional | right to left |
| 14 | = *= /= %= += -= <<= >>= >>>= &= ^= |= | assignment | right to left |
| 15 | , | comma | left to right |
This follows Macromedia’s own table in the Flash MX 2004 ActionScript reference,
which places each Flash 4 word operator beside the symbol that replaced it. That table
leaves out === and !==; they sit with ==, as in
ECMA-262.
Every operator
The player column is the first Flash Player that runs the operator, as Macromedia’s references give it. Flash 5 is player 5 and Flash MX is player 6.
| Operator | Name | Does | Player |
|---|---|---|---|
+ | addition | Adds numbers, or joins strings if either side is a string. | 4 |
- | subtraction, negation | Subtracts, or with one operand negates. | 4 |
* | multiplication | Multiplies. | 4 |
/ | division | Divides; dividing by zero gives Infinity, -Infinity or NaN. | 4 |
% | modulo | The remainder of a division, also for fractions: 5.5 % 2 is 1.5. | 4 |
++ -- | increment, decrement | Adds or subtracts 1. Before the operand, gives the new value; after it, the old one. | 4 |
= | assignment | Sets a variable, property or element, and gives the value set. | 4 |
+= -= *= /= %= | compound assignment | a += b is a = a + b, and so on. | 4 |
& | ^ ~ | bitwise and, or, exclusive or, not | Work on the operands as 32-bit integers. | 5 |
<< >> >>> | shifts | Left shift, right shift keeping the sign, and right shift filling with zeros. | 5 |
&= |= ^= <<= >>= >>>= | bitwise assignment | As the compound assignments. | 5 |
== != | equality, inequality | Compare after converting to a common type. Objects, arrays and clips are equal only to themselves. | 5 |
=== !== | strict equality, inequality | Compare without converting: values of different types are never equal. | 6 |
< > <= >= | comparison | Compare numbers, or two strings by character code. | 4 |
&& || | logical and, or | Evaluate the right side only if needed, and give the value of the side that decided, not a boolean: name || "guest". | 4 |
! | logical not | Converts to a boolean and inverts it. | 4 |
?: | conditional | a ? b : c gives b if a is true, else c. | 4 |
, | comma | Evaluates both sides and gives the right one; used in for headers. | 4 |
. | dot | A property, method or child clip of an object or timeline. | 4 |
[] | array access, array literal | A property or element by a computed name or index, or a new array. | 4 |
{} | object literal | A new Object with the listed properties. | 5 |
() | parentheses | Groups an expression, or calls a function. | 4 |
new | new | Calls a constructor to make an object: new Date(). | 5 |
delete | delete | Removes a property or a variable, and gives true if it did. Protected built-in properties stay. | 5 |
typeof | typeof | Gives the type name as a string; see Data types. | 5 |
void | void | Evaluates its operand and gives undefined. | 5 |
instanceof | instanceof | x instanceof F is true if F.prototype is on x’s prototype chain. | 6 |
Missing from ECMA-262’s set: in as an operator (it exists only in
for..in) and regular expression literals.
Flash 4 operators
Flash 4 had separate operators for numbers and strings: ==,
< and + always worked on numbers, and words did the same
work for strings. Flash 5 made the symbol operators work on both and kept the words,
deprecated, so they still compile.
| Flash 4 | Does | Write instead |
|---|---|---|
add | Joins two strings; in Flash 4 written & | + |
eq | Strings are equal | == |
ne | Strings are not equal | != |
lt | String is less than | < |
gt | String is greater than | > |
le | String is less than or equal | <= |
ge | String is greater than or equal | >= |
and | Logical and | && |
or | Logical or | || |
not | Logical not | ! |
<> | Numbers are not equal, from Flash 2 | != |
The string operators always convert both sides to strings, so 10 lt 9
is true, comparing "10" with "9" character by character,
where 10 < 9 is false.