Block statement - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

function declarations

Variables declared with var or created by function declarations in non-strict mode do not have block scope. Variables introduced within a block are scoped to the containing function or script, and the effects of setting

Block scoping rules with let, const, class, or function declaration in strict mode

By contrast, identifiers declared with let, const, and class do have block scope:

Block scoping rules with let, const, class, or function declaration in strict mode

By contrast, identifiers declared with let, const, and class do have block scope:

Block scoping rules with let, const, class, or function declaration in strict mode

By contrast, identifiers declared with let, const, and class do have block scope:

Block scoping rules with let, const, class, or function declaration in strict mode

By contrast, identifiers declared with let, const, and class do have block scope:

Using a block statement as the body of a for loop

A for loop accepts a single statement as its body.

using declarations in a block

You can declare variables with using or await using in a block, which causes the object stored in the variable to be disposed when control exits the block. For more information, see resource management.

using declarations in a block

You can declare variables with using or await using in a block, which causes the object stored in the variable to be disposed when control exits the block. For more information, see resource management.

resource management

You can declare variables with using or await using in a block, which causes the object stored in the variable to be disposed when control exits the block. For more information, see resource management.

Learn how to contribute

This page was last modified on Jul 29, 2025 by MDN contributors.

Expressions and operators

Numbers and strings

Representing dates & times

Regular expressions

Indexed collections

JavaScript typed arrays