Favorites

JavaScript Block statement Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Block statement
JavaScript Control FlowThis statement is supported by all modern browsers.
Updated 28th November 2026

A block statement groups several statements inside curly braces, and creates a new scope for let, const and class declarations.

Description

A block statement, a pair of curly braces, groups zero or more statements so they can be used where one statement is expected, such as after if or for. Each block also creates a scope: variables declared inside it with let, const or class aren't visible outside. Variables declared with var ignore block scope.

Blocks are most often seen as the bodies of if, for, while and function statements, but a block can also stand on its own. A standalone block is occasionally useful to limit how long a temporary variable exists, or to reuse a variable name, such as giving each case of a switch its own scope by wrapping it in braces.

Function declarations inside blocks are block-scoped in strict mode, but have confusing legacy behavior in non-strict scripts, so it's best to declare functions at the top level of a script, module or function, or to use const with a function expression inside blocks.

Syntax

{
  statements
}

Example

{
  const message = 'inside';
  var leaky = 'var ignores blocks';
  console.log(message);
}
console.log(typeof message, leaky);

Browser Support

The following information will show you the current browser support for the Block statement statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee