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)

PrecedenceOperator(s)CategorySimple Meaning
20()GroupingChanges order of execution
19. [] () newMember/CallAccess properties, call functions
18++ --PostfixIncrement/Decrement after use
17! ~ + - typeof void deleteUnaryOne-operand operators
16**ExponentiationPower
15* / %MultiplicativeMultiply, divide, remainder
14+ -AdditiveAdd, subtract
13<< >> >>>ShiftBit shifts
12< <= > >= in instanceofRelationalCompare values
11== != === !==EqualityCheck equality
10&Bitwise ANDBitwise AND
9^Bitwise XORBitwise XOR
8|Bitwise ORBitwise OR
7&&Logical ANDBoth must be true
6||Logical ORAny must be true
5??Nullish CoalescingFallback for null/undefined
4?:TernaryConditional operator
3= += -= *= /= %= **=AssignmentAssign values
2yieldGeneratorPauses generator
1,CommaEvaluates multiple expressions

Operator Associativity (Evaluation Direction)

Operator TypeAssociativitySimple Meaning
Most binary operators (+, -, *, /)Left to RightEvaluated from left
Assignment (=)Right to LeftAssigned from right
Exponentiation (**)Right to LeftPower evaluated right first
Ternary (?:)Right to LeftConditional nesting

Parentheses and Precedence

Parentheses () always have the highest priority and are used to control evaluation order.

Example FormEffect
(a + b) * cAddition 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.