Operator Precedence
EasyIn plain terms
Operators have a precedence order - multiplication before addition, etc. Use parentheses () to make order explicit and improve readability. When unsure, add parentheses.
What you need to know
- •*, / before +, -
- •! before && before ||
- •Use () for clarity
Try it yourself
Copy the code below and run it in your browser console or a code editor:
2 + 3 * 4; // 14 (3*4 first)
(2 + 3) * 4; // 20
!true || false; // false (! has higher precedence)
!(true || false); // false
// Complex - use parentheses for clarity
const result = (a > 0 && b < 10) || (c === null);Learn more
Dive deeper with these trusted resources: