Learn JavaScript
❯ operators.op_precedence

Operator Precedence in JavaScript

$concept

Precedence decides grouping without parentheses: member access and calls first, then unary (!, typeof, await), then **, then *//%, then +-, then comparisons, then logicals (&& over ||), with assignment and yield/ternary near the bottom and comma last. The ??-with-&&/|| restriction (mandatory parentheses) is precedence made into syntax.

Know the big ladder (unary → multiplicative → additive → comparison → logical → ternary/assignment) and parenthesize the rest — especially mixed ??/||, ternaries inside templates, and ! with comparisons (!x === y parses as (!x) === y).

$how it works
1

The big ladder

Unary, then *//%, then +-, then comparisons, then &&, then ||, then ?: and assignment — memorize this spine.

2

?? forces grouping

a ?? b || c is a syntax error, not a precedence question — the language demands visible grouping.

3

! binds tightly

!x === y means (!x) === y — negate comparisons as !(x === y) or restructure.

4

Parenthesize the exotic

Mixing ** with unary (-2 ** 2 is actually an error — write (-2) ** 2), nested ternaries, comma sequences: all get parens.

$example
console.log(2 + 3 * 4);
console.log(true || false && false);
console.log((2 + 3) * 4);
Output
14
true
20
1* outranks +: 2 + 12 = 14.
2&& outranks ||: true || (false && false) = true.
3Parentheses override everything: 5 * 4 = 20.
$use cases
Reading dense expressions via the precedence spine
Grouping every ?? combination explicitly (the compiler insists)
Parenthesizing !-with-comparison and nested ternaries
Writing (-2) ** 2 instead of the syntax-error form

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.