JS-026

Beginner3 min~3 min read#operators#precedence#math
Operator Precedence
Order of operator execution
Goal
Understand the order in which JavaScript evaluates operators.
Explanation
- When an expression has several operators, JavaScript does not always go left to right — it follows precedence rules.
- Multiplication and division have higher precedence than addition and subtraction.
- Parentheses are always evaluated first.
- The order of execution can completely change the result of an expression.
- When in doubt, use parentheses to make the code clearer.
Analogy
Imagine a line at a store. Some customers have priority and go first. Some operators run before others in the same way.
Code
console.log(2 + 3 * 4);
console.log((2 + 3) * 4);Result: 14 20
Common mistake
Beginners often expect JavaScript to always evaluate an expression left to right. In reality, it follows operator precedence rules.
Remember
- ✦ Multiplication and division run first.
- ✦ Parentheses have the highest precedence.
- ✦ Operator order affects the result.
Quick Quiz
What does 2 + 3 * 4 return?