MENU
Precedence & Associativity
P recedence determines the order in which operators are evaluated in an expression. For example, 3 + 4 * 5returns 23, because * is evaluated before +. * is said to have higher precedence than +.Associativity determines the order of evaluation for operators of the same precedence. For example, a = b = cwill assign both variables a and b the value of c, because b = c will be evaluated first, as = has right-to-left associativity.
| Pr. | Operator type | Ass. | Syntax |
| 21 | Grouping | n/a | ( ... ) |
| 20 | Member Access | LTR | ... . ... |
| Computed Member Access | LTR | ... [ ... ] | |
| new (with argument list) | n/a | new ... ( ... ) | |
| Function Call | LTR | ... ( ... ) | |
| 19 | new (without argument list) | RTL | new ... |
| 18 | Postfix Increment | n/a | ... ++ |
| Postfix Decrement | n/a | ... -- | |
| 17 | Logical NOT | RTL | ! ... |
| Bitwise NOT | RTL | ~ ... | |
| Unary Plus | RTL | + ... | |
| Unary Negation | RTL | - ... | |
| Prefix Increment | RTL | ++ ... | |
| Prefix Decrement | RTL | -- ... | |
| typeof | RTL | typeof ... | |
| void | RTL | void ... | |
| delete | RTL | delete ... | |
| await | RTL | await ... | |
| 16 | Exponentiation | RTL | ... ** ... |
| 15 | Multiplication | LTR | ... * ... |
| Division | LTR | ... / ... | |
| Remainder | LTR | ... % ... | |
| 14 | Addition | LTR | ... + ... |
| Subtraction | LTR | ... - ... | |
| 13 | Bitwise Left Shift | LTR | ... << ... |
| Bitwise Right Shift | LTR | ... >> ... | |
| Bitwise Unsigned Right Shift | LTR | ... >>> ... | |
| 12 | Less Than | LTR | ... < ... |
| Less Than Or Equal | LTR | ... <= ... | |
| Greater Than | LTR | ... > ... | |
| Greater Than Or Equal | LTR | ... >= ... | |
| in | LTR | ... in ... | |
| instanceof | LTR | ... instanceof ... | |
| 11 | Equality | LTR | ... == ... |
| Inequality | LTR | ... != ... | |
| Strict Equality | LTR | ... === ... | |
| Strict Inequality | LTR | ... !== ... | |
| 10 | Bitwise AND | LTR | ... & ... |
| 9 | Bitwise XOR | LTR | ... ^ ... |
| 8 | Bitwise OR | LTR | ... | ... |
| 7 | Logical AND | LTR | ... && ... |
| 6 | Logical OR | LTR | ... || ... |
| 5 | Nullish coalescing operator | LTR | ... ?? ... |
| 4 | Conditional | RTL | ... ? ... : ... |
| 3 | Assignment | RTL | ... = ... |
| ... += ... | |||
| ... -= ... | |||
| ... **= ... | |||
| ... *= ... | |||
| ... /= ... | |||
| ... %= ... | |||
| ... <<= ... | |||
| ... >>= ... | |||
| ... >>>= ... | |||
| ... &= ... | |||
| ... ^= ... | |||
| ... |= ... | |||
| 2 | yield | RTL | yield ... |
| yield* | RTL | yield* ... | |
| 1 | Spread | n/a | ... ... |
| 0 | Comma / Sequence | LTR | ... , ... |
RESETRUNFULL
<!DOCTYPE html><html><body><script>
console.log(3*(5+2)); // 21console.log(2**2**2*3%10); // 8
</script></body><html>Note that an assignment statement returns the value being assigned. Because of the right-to-left associativity of some operators, you can declare multiple variables/functions using the operators continuously in a row:
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var x = y = 7;console.log(z=x+=1);f = a => b => x;console.log(f()()); // f() and 'a' return a function
</script></body><html>