> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/grammar/statement/other/block.md).

# block

use { ... } to group statements.

[JS](/web/js.md) ⟩ [statement](/web/js/grammar/statement.md) ⟩ [other](/web/js/grammar/statement/other.md) ⟩ block

{% hint style="success" %}
([statement](/web/js/grammar/statement.md)) <mark style="color:yellow;">**use**</mark> <mark style="color:blue;">**`{ ... }`**</mark> to <mark style="color:yellow;">**group statements**</mark>.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:red;">**not**</mark>  <mark style="color:purple;">**block**</mark>：

* [object literal](/web/js/val/obj/create/obj.md) / [class](/web/js/val/class.md) / [switch](/web/js/grammar/statement/flow/branch/switch.md)：  <mark style="color:red;">**no**</mark> [block scope](/web/js/grammar/statement/other/block/block.md):exclamation:
* [function](/web/js/val/func.md)：its [scope](/web/js/scope/function.md) is <mark style="color:yellow;">**different**</mark> from a [block scope](/web/js/grammar/statement/other/block/block.md):exclamation:

📗 [You Don't Know JS Yet: Scopes & Closrues](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch6.md#scoping-with-blocks)
{% endhint %}

{% hint style="warning" %}
[break](/web/js/grammar/statement/flow/jump/break.md) / [continue](/web/js/grammar/statement/flow/jump/continue.md)&#x20;

* <mark style="color:red;">**won't**</mark> operate <mark style="color:yellow;">**across**</mark> an [IIFE](/web/js/val/func/expr/iife.md) [function boundary](/web/js/val/func/boundary.md) to control an <mark style="color:yellow;">**outer**</mark> [loop](/web/js/grammar/statement/loop.md) / <mark style="color:purple;">**block**</mark>.

📗 [You Don't Know JS Yet: Scopes & Closrues](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch6.md#invoking-function-expressions-immediately)
{% endhint %}

{% hint style="danger" %}
if the <mark style="color:yellow;">**code**</mark> you need to <mark style="color:yellow;">**wrap**</mark> a [scope](/web/js/scope.md) <mark style="color:yellow;">**around**</mark> has [return](/web/js/grammar/statement/flow/jump/return.md) / [this](/web/js/concept/execution-context/this.md) / [break](/web/js/grammar/statement/flow/jump/break.md) / [continue](/web/js/grammar/statement/flow/jump/continue.md) in it：

* <mark style="color:red;">**don't**</mark>**&#x20;**<mark style="color:yellow;">**use**</mark> [function](/web/js/val/func.md) / [IIFE](/web/js/val/func/expr/iife.md) (which has <mark style="color:yellow;">**its own**</mark> [function boundary](/web/js/val/func/boundary.md)):exclamation:
* use [block](/web/js/grammar/statement/other/block.md) instead.

📗 [You Don't Know JS Yet: Scopes & Closrues](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch6.md#function-boundaries)
{% endhint %}

{% hint style="info" %}
A "[variable](/web/js/variable.md)" is just a [property](/web/js/val/obj/prop.md) of the [environment record](/web/js/concept/execution-context/lexical-environment/environment-record.md) (associated with the <mark style="color:yellow;">**currently executing**</mark> [block](/web/js/grammar/statement/other/block.md) /[function](/web/js/val/func.md) /[module](/web/js/module.md) /<mark style="color:yellow;">**script**</mark>).&#x20;
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* [block scope](/web/js/grammar/statement/other/block/block.md)
  {% endtab %}

{% tab title="👥 相關" %}

* :information\_source:[braces {}](/web/js/grammar/token/punctuator/braces.md) punctuator is used in block.
  {% endtab %}

{% tab title="📘 手冊" %}

* [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) ⟩ [Others](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#others) ⟩ [block](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)
  {% endtab %}
  {% endtabs %}
