The Block { } Operators
Definition
The block { } operators (curly braces) are used to group statements together in a single block.
Example
// Everything inside here is part of a block
showMessage();
loadDashboard();
}
Grouping Code (Block Statements)
The most basic use of { } is to bundle lines of code together. This is crucial for control structures like loops and conditionals because JavaScript expects only one statement after them.
Note
In JavaScript, the { } symbol serves different purposes depending on how it is used:
Bundle code inside if statements:
// bundled code lines
}
Bundle code inside loops:
// bundled code lines
}
Limit visability (scope):
// standalone code
}
Object literal syntax:
Object destructuring:
Named imports and exports:
See Also:
Browser Support
{ } is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |