Operators (JavaScript)
Operators fall into the following categories:
| Operators | Description |
|---|---|
| Assignment operators (JavaScript) | = += -= *= /= %=&= |= ^= <<= >>= >>>= |
| Comparison operators (JavaScript) | == != === !== > >=< <= |
| Arithmetic operators (JavaScript) | + - * / % ++ (post-increment) ++ (pre-increment) -- (post-decrement) -- (pre-decrement) - (negation) + (unary plus) |
| Bitwise operators (JavaScript) | & | ~ ^ << >> >>> |
| Logical operators (JavaScript) | && || ! |
| String operators (JavaScript) | + += |
| List operators (JavaScript) | + - * / |
| Special operators (JavaScript) | ?: , delete function new this typeof void . [] |
The following table lists operator precedence and associativity.
Operators with lower precedence evaluate first left-to-right or right-to-left
as listed. Parentheses can be used to change the order of evaluation;
parenthesized expressions are evaluated first inner to outer.
| Precedence | Operator | Associativity |
|---|---|---|
| 1 | . [] | left-to-right |
| new | right-to-left | |
| 2 | () | left-to-right |
| 3 | ++ -- | not applicable |
| 4 | ! ~ - (negation) + (unary plus) typeof void delete | right-to-left |
| 5 | * / % | left-to-right |
| 6 | + - | left-to-right |
| 7 | << >> >>> | left-to-right |
| 8 | > >=< <= | left-to-right |
| 9 | == != === !== | left-to-right |
| 10 | & | left-to-right |
| 11 | ^ | left-to-right |
| 12 | | | left-to-right |
| 13 | && | left-to-right |
| 14 | || | left-to-right |
| 15 | ?: | right-to-left |
| 16 | = += -= *= /= %=&= |= ^= <<= >>= >>>= | right-to-left |
| 17 | , | left-to-right |