Precedence Levels Overview
What you'll learn: You'll discover how JavaScript ranks operators from highest to lowest priority, determining which operations happen first in complex expressions.
Understanding the Hierarchy
Think of operator precedence like the order of operations you learned in math class (PEMDAS). JavaScript has a similar ranking system that decides which operators "win" when multiple operators appear together without parentheses.
From highest precedence (happens first) to lowest (happens last), here are the major groups:
Highest Priority
- Grouping
()— Forces evaluation first, just like parentheses in math - Member Access
.and[]— Accessing object properties
High Priority
- Unary operators —
!,typeof,++,--,+(unary),-(unary) - Exponentiation
**
Medium-High Priority
- Multiplication/Division/Remainder —
*,/,% - Addition/Subtraction —
+,-
Medium Priority
- Comparison operators —
<,>,<=,>= - Equality operators —
==,===,!=,!==
Medium-Low Priority
- Logical AND
&& - Logical OR
||
Lower Priority
- Ternary operator
? : - Assignment operators —
=,+=,-=, etc.
Lowest Priority
- Comma operator
,— Evaluates multiple expressions, returns the last
Why This Matters
When you write 5 + 3 * 2, JavaScript evaluates 3 * 2 first (result: 6), then adds 5 (final: 11) because multiplication has higher precedence than addition. Without understanding precedence, you might expect 16!
Key Takeaway: Operator precedence determines the order of evaluation in expressions, with grouping (parentheses) at the top and comma at the bottom—use parentheses when in doubt to make your intentions clear.