Round Brackets
in JavaScript
This is an entry in Marek's JavaScript Compendium . Last updated 2020-01-22.
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.
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);
// prettier-ignore
(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.
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");
//---left--^--------right------------
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.
openModal();