Course contentsShow
← JavaScript
Lesson 270 of 2,7237. Arithmetic and OperatorsFree lesson

Using Parentheses to Override Precedence

How grouping with `()` forces evaluation order, making `(2 + 3) * 4` equal 20 instead of 14.

Using Parentheses to Override Precedence

What you'll learn: How to use parentheses to control the exact order that JavaScript evaluates your arithmetic operations.

The Problem Without Parentheses

You've learned that JavaScript has rules about which operators run first (precedence). For example, multiplication happens before addition, so 2 + 3 * 4 equals 14 (not 20), because JavaScript calculates 3 * 4 first, then adds 2.

But what if you want addition to happen first?

Parentheses Force Your Order

Parentheses () are the ultimate override. Whatever is inside parentheses gets evaluated first, no matter what the normal precedence rules say.

2 + 3 * 4     // 14 (multiplication first: 2 + 12)
(2 + 3) * 4   // 20 (parentheses first: 5 * 4)

In the second example, the parentheses force JavaScript to calculate 2 + 3 first, giving you 5. Only then does it multiply by 4.

Think of It Like a To-Do List

Imagine JavaScript has a to-do list for your calculation. Normally, it sorts that list by precedence rules. But parentheses are like writing "DO THIS FIRST!" in big red letters — JavaScript must complete what's in parentheses before moving on.

10 - 2 + 3        // 11 (left to right: 8 + 3)
10 - (2 + 3)      // 5 (parentheses first: 10 - 5)

100 / 5 * 2       // 40 (left to right: 20 * 2)
100 / (5 * 2)     // 10 (parentheses first: 100 / 10)

Key Takeaway: Parentheses () let you override JavaScript's default operator precedence, forcing the enclosed expression to evaluate first — turning (2 + 3) * 4 into 20 instead of 14.