Round Brackets

in JavaScript

This is an entry in Marek's JavaScript Compendium. Last updated 2020-01-22.

Round brackets, or just brackets, or parentheses (singular: parenthesis) are punctuation marks in JavaScript, consisting of the opening round bracket ( and closing round bracket ).

( )

Round brackets have multiple meanings in JavaScript, depending on the context.

Grouping expressions

Round brackets are used to group expressions when we need an order of operations that isn't the default order.

When we talk about order of operations (a concept from mathematics), in programming this exists in the form of operator precedence.

10 * x + 1;
10 * (x + 1);
(10 * x) + 1;

You can recognize brackets that are used for grouping by the fact that they're always placed directly after an operator (like * or + in the above example).

If an opening bracket is placed directly after an expression instead, then it's a function call.

Function call expression

When an opening bracket directly follows an expression, it's the start of a function call expression.

The opening bracket in a function call expression is the middle of the expression, and it marks the two parts of a function call:

sendMessage("jon", "Meeting at noon");
  • On the left: the expression that provides the function to be called
  • On the right: a list of expressions that provide the arguments to the function call

It's common enough to call a function and provde no arguments, which means that the opening bracket is followed by a closing bracket with nothing in between.