Operator Precedence Reference

Operator precedence tables for JavaScript, Python, and C (highest to lowest precedence).

Back to all tools on ToolForge

More in Developer Tools

About Operator Precedence Reference

This operator precedence reference provides side-by-side tables for JavaScript, Python, and C so you can quickly verify expression evaluation order and associativity.

Use it to debug ambiguous expressions, avoid precedence bugs, and improve readability with explicit parentheses where needed.

Quick Example: In 2 + 3 * 4, multiplication happens first: 2 + (3 * 4) = 14, not (2 + 3) * 4 = 20.

JavaScript Operator Precedence

LevelPrecedenceOperatorsAssociativityDescription
121() [] . new ?.L→RMember access, function call
220new (with args)R→LObject instantiation
319++ -- (postfix)L→RPostfix increment/decrement
418! ~ + - ++ -- typeof void deleteR→LUnary operators
517**R→LExponentiation
616* / %L→RMultiplicative
715+ -L→RAdditive
814<< >> >>>L→RBitwise shifts
913< > <= >= in instanceofL→RRelational
1012== != === !==L→REquality
1111&L→RBitwise AND
1210^L→RBitwise XOR
139|L→RBitwise OR
148&&L→RLogical AND
157|| ??L→RLogical OR / Nullish coalescing
166? :R→LTernary conditional
175= += -= *= /= %= &= |= ^= <<= >>= >>>= **=R→LAssignment operators
184yield yield*R→LGenerator yield
193=>R→LArrow function
201,L→RComma (sequence)

Python Operator Precedence

LevelPrecedenceOperatorsAssociativityDescription
118() [] {} .L→RGrouping, indexing, attribute
217**R→LExponentiation
316+x -x ~xR→LUnary plus, minus, bitwise NOT
415notR→LLogical NOT
514* / // % @L→RMultiplication, division, floor div, mod, matrix
613+ -L→RAddition, subtraction
712<< >>L→RBitwise shifts
811&L→RBitwise AND
910^L→RBitwise XOR
109|L→RBitwise OR
118in not in is is not < <= > >= != ==L→RComparisons, membership, identity
127notR→LBoolean NOT
136andL→RBoolean AND
145orL→RBoolean OR
154if elseR→LConditional expression
163:=R→LWalrus operator (assignment expression)
172= += -= *= /= //= %= **= &= |= ^= <<= >>=R→LAugmented assignment
181lambdaR→LLambda expression

C Operator Precedence

LevelPrecedenceOperatorsAssociativityDescription
115() [] -> .L→RFunction call, array subscript, member access
214++ -- (postfix) () (cast)R→LPostfix increment/decrement, type cast
313++ -- (prefix) + - ! ~ * & sizeof _AlignofR→LUnary operators
412* / %L→RMultiplicative
511+ -L→RAdditive
610<< >>L→RBitwise shifts
79< <= > >=L→RRelational
88== !=L→REquality
97&L→RBitwise AND
106^L→RBitwise XOR
115|L→RBitwise OR
124&&L→RLogical AND
133||L→RLogical OR
142? :R→LConditional (ternary)
151= += -= *= /= %= <<= >>= &= ^= |=R→LAssignment
160,L→RComma operator

Common Precedence Pitfalls

1. Bitwise AND vs Equality

// WRONG: & has LOWER precedence than ==
if (x & 1 == 0)  // Evaluates as: x & (1 == 0) = x & 0 = 0

// CORRECT: Use parentheses
if ((x & 1) == 0)  // Checks if x is even

2. Logical AND vs Logical OR

// && binds tighter than ||
if (a || b && c)  // Means: a || (b && c), NOT (a || b) && c

// For clarity, use parentheses
if (a || (b && c))

3. Assignment in Conditions

// C/JavaScript: = has very low precedence
if (x = y && z)  // Means: x = (y && z), assigns boolean!

// Use == for comparison
if (x == (y && z))

// Intentional assignment (C idiom)
while ((c = getchar()) != EOF)  // Read char until EOF

4. Python Chained Comparisons

# Python allows chained comparisons
if 0 < x < 10:  # Means: (0 < x) and (x < 10)

# JavaScript requires explicit logic
if (x > 0 && x < 10)  // Cannot chain in JS

Operator Associativity Examples

ExpressionAssociativityEvaluates AsResult (a=1,b=2,c=3)
a - b - cL→R(a - b) - c-4
a ** b ** cR→La ** (b ** c)1^8 = 1
a = b = cR→La = (b = c)All equal 3
a && b && cL→R(a && b) && ctrue if all truthy
a ? b : c ? d : eR→La ? b : (c ? d : e)Nested conditional

Frequently Asked Questions

What is operator precedence?
Operator precedence is the default order a language uses to evaluate operators in an expression. Higher-precedence operators run first unless parentheses override the order.
What is associativity in operators?
Associativity decides direction when two operators have the same precedence. For example, subtraction is usually left-to-right, while assignment is usually right-to-left.
Why does 2 + 3 * 4 equal 14 and not 20?
Because multiplication has higher precedence than addition. The expression is read as 2 + (3 * 4). To force 20, write (2 + 3) * 4.
What is the precedence of logical operators?
In most languages, NOT binds tighter than AND, and AND binds tighter than OR. So !a && b || c is typically evaluated as ((!a) && b) || c.
How does Python's precedence differ from JavaScript?
Python and JavaScript are similar in many basics, but Python uses words like and/or/not and supports chained comparisons such as a < b < c. JavaScript uses symbols like && and || and does not support that comparison chain syntax the same way.
When should I use parentheses?
Use parentheses whenever intent could be misread, especially with mixed arithmetic, bitwise, or logical operators. Even if optional, they make code easier to review and maintain.