Operator Precedence in JavaScript
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).
The big ladder
Unary, then *//%, then +-, then comparisons, then &&, then ||, then ?: and assignment — memorize this spine.
?? forces grouping
a ?? b || c is a syntax error, not a precedence question — the language demands visible grouping.
! binds tightly
!x === y means (!x) === y — negate comparisons as !(x === y) or restructure.
Parenthesize the exotic
Mixing ** with unary (-2 ** 2 is actually an error — write (-2) ** 2), nested ternaries, comma sequences: all get parens.
console.log(2 + 3 * 4);console.log(true || false && false);console.log((2 + 3) * 4);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.