JavaScript operator precedence defines the order in which operators are evaluated in an expression. Operators with higher precedence are evaluated first. Parentheses () can be used to change the default evaluation order.
What Is Operator Precedence in JavaScript?
When multiple operators are used in one expression, JavaScript follows a fixed priority order to decide which operation runs first. Understanding precedence helps avoid logic errors in expressions.
JavaScript Operator Precedence Table (High → Low)
| Precedence | Operator(s) | Category | Simple Meaning |
|---|---|---|---|
| 20 | () | Grouping | Changes order of execution |
| 19 | . [] () new | Member/Call | Access properties, call functions |
| 18 | ++ -- | Postfix | Increment/Decrement after use |
| 17 | ! ~ + - typeof void delete | Unary | One-operand operators |
| 16 | ** | Exponentiation | Power |
| 15 | * / % | Multiplicative | Multiply, divide, remainder |
| 14 | + - | Additive | Add, subtract |
| 13 | << >> >>> | Shift | Bit shifts |
| 12 | < <= > >= in instanceof | Relational | Compare values |
| 11 | == != === !== | Equality | Check equality |
| 10 | & | Bitwise AND | Bitwise AND |
| 9 | ^ | Bitwise XOR | Bitwise XOR |
| 8 | | | Bitwise OR | Bitwise OR |
| 7 | && | Logical AND | Both must be true |
| 6 | || | Logical OR | Any must be true |
| 5 | ?? | Nullish Coalescing | Fallback for null/undefined |
| 4 | ?: | Ternary | Conditional operator |
| 3 | = += -= *= /= %= **= | Assignment | Assign values |
| 2 | yield | Generator | Pauses generator |
| 1 | , | Comma | Evaluates multiple expressions |
Operator Associativity (Evaluation Direction)
| Operator Type | Associativity | Simple Meaning |
|---|---|---|
Most binary operators (+, -, *, /) | Left to Right | Evaluated from left |
Assignment (=) | Right to Left | Assigned from right |
Exponentiation (**) | Right to Left | Power evaluated right first |
Ternary (?:) | Right to Left | Conditional nesting |
Parentheses and Precedence
Parentheses () always have the highest priority and are used to control evaluation order.
| Example Form | Effect |
|---|---|
(a + b) * c | Addition runs before multiplication |
a + (b * c) | Multiplication runs before addition |
Common Mistakes with Operator Precedence
-
Assuming left-to-right execution always
-
Forgetting parentheses in complex expressions
-
Mixing logical and comparison operators without grouping
-
Misunderstanding
&&vs||priority -
Confusing
==and===precedence
Summary
JavaScript operator precedence defines the evaluation order of expressions. Operators like grouping (), member access, unary, arithmetic, comparison, logical, ternary, and assignment follow a strict priority order. Using parentheses improves clarity and prevents unexpected results in complex expressions.