An operator combines one, two or three operands into a value. When an expression has
several, the one with the higher precedence goes first, and operators of the same
precedence go left to right, except the assignments and ?:, which go right
to left. Parentheses override both.
Precedence
From the highest to the lowest, as Adobe’s documentation gives it. Operators in one row have the same precedence.
| Level | Group | Operators | Associativity |
|---|---|---|---|
| 1 | Primary | [] {x:y} () f(x) new x.y x[y] <></> @ :: .. | Left to right |
| 2 | Postfix | x++ x-- | – |
| 3 | Unary | ++x --x + - ~ ! delete typeof void | Right to left |
| 4 | Multiplicative | * / % | Left to right |
| 5 | Additive | + - | Left to right |
| 6 | Bitwise shift | << >> >>> | Left to right |
| 7 | Relational | < > <= >= as in instanceof is | Left to right |
| 8 | Equality | == != === !== | Left to right |
| 9 | Bitwise AND | & | Left to right |
| 10 | Bitwise XOR | ^ | Left to right |
| 11 | Bitwise OR | | | Left to right |
| 12 | Logical AND | && | Left to right |
| 13 | Logical OR | || | Left to right |
| 14 | Conditional | ?: | Right to left |
| 15 | Assignment | = *= /= %= += -= <<= >>= >>>= &= ^= |= &&= ||= | Right to left |
| 16 | Comma | , | Left to right |
Adobe’s precedence table leaves out &&= and ||=,
though its language reference lists both; they are assignments.
Arithmetic
| Operator | Meaning |
|---|---|
a + b | Adds numbers. When either side is a String, joins them as strings; when both are XML or XMLList, joins them into an XMLList. |
a - b, a * b | Subtracts, multiplies. |
a / b | Divides, always giving a Number; division by zero gives Infinity, -Infinity or NaN. |
a % b | The remainder, with the sign of a; works on fractions too: 5.5 % 2 is 1.5. |
-a, +a | Negates; converts to a number. |
++x, --x | Adds or subtracts 1 and gives the new value. |
x++, x-- | Adds or subtracts 1 and gives the old value. |
Comparison
| Operator | Meaning |
|---|---|
a == b, a != b | Equal, not equal, converting types first: 5 == "5" is true, and null == undefined is true. Objects are equal only if they are the same object; XML values compare by content. |
a === b, a !== b | Strictly equal, not equal: without conversion, so 5 === "5" is false. The numeric types count as one type: int(5) === 5.0 is true. |
<, >, <=, >= | Order. Two strings compare by character codes, so "Z" < "a"; otherwise both sides become numbers, and any comparison with NaN is false. |
Logical
| Operator | Meaning |
|---|---|
a && b | Gives a if it converts to false, otherwise b. b is evaluated only if needed. |
a || b | Gives a if it converts to true, otherwise b: name || "anonymous". |
!a | The opposite of a converted to Boolean. |
c ? a : b | a when c converts to true, otherwise b; only one is evaluated. |
Bitwise
The operands are converted to 32-bit integers first. The results are
int, except for >>>, whose result is
uint. Shift counts use only their low 5 bits.
| Operator | Meaning |
|---|---|
a & b, a | b, a ^ b | AND, OR, exclusive OR of each bit: (colour >> 16) & 0xFF is the red of 0xRRGGBB. |
~a | Inverts every bit: ~0 is −1. |
a << n | Shifts left, filling with zeros. |
a >> n | Shifts right, copying the sign bit. |
a >>> n | Shifts right, filling with zeros. |
Assignment
x = v stores v in a variable, property or element and gives
v, so a = b = 0 sets both. Each compound form
x op= v means x = x op v, with x evaluated once:
*= /= %= += -=
<<= >>= >>>=
&= ^= |= &&=
||=. += also appends to a string or to an
XMLList.
Type and property operators
| Operator | Meaning |
|---|---|
x is T | Whether x is of class or interface T, counting subclasses and implemented interfaces. |
x as T | x if it is of type T, otherwise null. |
x instanceof F | Whether F.prototype is on the prototype chain of x; it does not see interfaces. |
typeof x | A string: "number", "string", "boolean", "function", "xml", "undefined" or "object". See Testing types. |
"name" in obj | Whether obj has the property, fixed or dynamic, own or inherited; for an array, whether the index is within range. |
delete obj.p, delete obj[k] | Removes a dynamic property, an array element (leaving a gap) or XML elements and attributes. Fixed properties and var variables cannot be deleted. Gives true when the property does not exist afterwards. |
void x | Evaluates x and gives undefined. |
new C(args) | Creates an instance of class C, or of a function used as a constructor. new C without parentheses also works. |
a, b | Evaluates a, then b, and gives b; mostly used in for headers. |
Access
| Operator | Meaning |
|---|---|
obj.name | A property or method by name; also separates the parts of a package name. |
obj[expr] | A property whose name is computed, or an array or vector element. Strict mode does not check names reached this way. |
ns::name | A name in namespace ns: flash_proxy::getProperty, obj.ns::[expr]. |
f(args) | Calls a function or method. |
Vector.<T> | Applies a type parameter, the only generic form in the language. |
E4X operators
These work on XML and XMLList values. See
XML and E4X for examples.
| Operator | Meaning |
|---|---|
x.child | The child elements named child, as an XMLList; x.* is every child element. |
x..name | Descendants named name at any depth; x..@id every id attribute below. |
x.@attr | An attribute; x.@* every attribute; x.@["data-id"] for a name that is not an identifier. |
x["name"] | A child by a computed name; list[0] an item of a list. |
x.(expr) | A filter: the items of x for which expr, evaluated with each item’s children and attributes in scope, is true: staff.employee.(@id == "42"). |
ns::name | An element or attribute in an XML namespace: x.soap::Body. |
{expr} in a literal | Inserts a value into an XML literal: <item id={n}>{label}</item>. |
<>…</> | An XMLList literal. |
a + b, x += y | Joins XML values into an XMLList; appends to one. |
delete x.child, delete x.@attr | Removes elements or attributes from the tree. |