The Grouping () Operator
The result above evaluates to 25 instead of 17 because (2 + 3) is evaluated first.
Definition
The () operator is called the grouping operator.
It overrides normal operator precedence by letting the code inside the parentheses is evaluated first.
Precedence
The grouping operator has the highest possible precedence in JavaScript.
Grouping allows lower-precedence calculations (like addition) to force-execute ahead of higher-precedence operations (like multiplication).
Not Always Grouping
Parentheses are also used in other parts of the JavaScript syntax (not only grouping):
- Wrapping if conditions:
if (age > 18) - Invoking functions:
myFunction() - Controlling loops:
for (let i = 0; i < 10; i++)
Browser Support
() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |