High precedence
Member access, calls, grouping and unary operations bind tightly.
Operator precedence decides which parts of an expression run first. Parentheses make that decision visible.
1 + 2 * 3; // 7 (1 + 2) * 3; // 9 true || false && false; // true
Operators & Expressions
JavaScript has a formal precedence order. Multiplication runs before addition, member access runs before most operations and assignment runs very late.
Knowing the basics is important, but professional code does not try to show off. If an expression mixes multiple operator families, parentheses make intent clear.
Precedence is not the same as evaluation side effects. Short-circuiting, function calls and assignment can still affect when something runs.
Member access, calls, grouping and unary operations bind tightly.
* and / run before + and -. Parentheses can override this.
&& binds tighter than ||. Parentheses help readers.
Assignment and comma happen late and should usually stay obvious.
Examples
const subtotal = itemCount * pricePerItem; const total = subtotal - (subtotal * discountRate); const canSubmit = hasName && (hasPlan || wantsDemo);
const canSubmit = hasName && hasPlan || wantsDemo && !isBlocked; // Legal, but readers must decode precedence before understanding intent.
Rules that matter
JavaScript operators are compact, but compact is not always clear. Convert values before comparing or calculating, use strict checks by default and add parentheses when a future reader would otherwise need to remember a precedence table.
Especially when combining arithmetic, comparison and logical operators.
Named intermediate values are often clearer than one clever line.
Basic math precedence still applies.
Logical expressions can surprise readers without grouping.
Use parentheses because JavaScript requires clear grouping there.
Assignment has low precedence and should not be hidden inside big expressions.
Production thinking
Precedence bugs are reading bugs. The code may be valid, but the reader misunderstands what it really means.
Complex conditions often control UI state. If precedence is misunderstood, users can get wrong labels, focus behavior or validation states.
Production review is faster when expressions explain themselves. Parentheses and named values are cheap clarity.
Conditional rendering expressions should be clear enough to trust when they affect headings, links and metadata.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Say the answer in plain language. If you can explain the operator behavior, you can debug the expression.
Chapter checkpoint
Finish this chapter by turning the lessons into a small practical proof.
Build a small example that combines three lessons from this chapter.
Can you explain the important tradeoff without reading from the page?