> 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/label.md).

# label

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

{% hint style="success" %}
([statement](/web/js/grammar/statement.md))&#x20;

prefixes a statement with an [identifier](/web/js/grammar/token/id.md) which you can refer to.&#x20;

```javascript
<label> : <statement>        // syntax
```

{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %} <mark style="color:purple;">**label**</mark> is <mark style="color:red;">**only**</mark>**&#x20;**<mark style="color:yellow;">**used by**</mark> [break](/web/js/grammar/statement/flow/jump/break.md) <mark style="color:yellow;">**/**</mark> [continue](/web/js/grammar/statement/flow/jump/continue.md).
{% endhint %}

{% hint style="warning" %}
( <mark style="color:yellow;">**nested**</mark> [loop](/web/js/grammar/statement/loop.md))

<mark style="color:purple;">**labeled**</mark> <mark style="color:yellow;">**statement**</mark> is <mark style="color:red;">**needed**</mark>&#x20;

* when you want to [**skip**](/web/js/grammar/statement/flow/jump/continue.md) <mark style="color:yellow;">**to**</mark> the <mark style="color:yellow;">**next iteration**</mark> of <mark style="color:yellow;">**an outer loop**</mark> that is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**the**</mark>**&#x20;**<mark style="color:red;">**nearest**</mark>**&#x20;**<mark style="color:yellow;">**enclosing**</mark> [loop](/web/js/grammar/statement/loop.md).
* when you want to [break](/web/js/grammar/statement/flow/jump/break.md) <mark style="color:yellow;">**out**</mark> <mark style="color:yellow;">**of**</mark> a statement that is <mark style="color:red;">**not**</mark>**&#x20;**<mark style="color:yellow;">**the**</mark>**&#x20;**<mark style="color:red;">**nearest**</mark>**&#x20;**<mark style="color:yellow;">**enclosing**</mark> [loop](/web/js/grammar/statement/loop.md) <mark style="color:yellow;">**/**</mark> [switch](/web/js/grammar/statement/flow/branch/switch.md).
  {% endhint %}

{% hint style="info" %}
The <mark style="color:yellow;">**namespace**</mark> for <mark style="color:purple;">**labels**</mark> is <mark style="color:red;">**different**</mark> than the namespace for [variable](/web/js/variable.md)(s) and [function](/web/js/val/func.md)(s), the <mark style="color:red;">**same**</mark> [identifier](/web/js/grammar/token/id.md) <mark style="color:green;">**can**</mark>**&#x20;**<mark style="color:yellow;">**be used as**</mark> <mark style="color:purple;">**label**</mark> <mark style="color:yellow;">**/**</mark> <mark style="color:orange;">**variable**</mark> or <mark style="color:orange;">**function**</mark> name.
{% endhint %}

{% hint style="warning" %}
"the [statement](/web/js/grammar/statement.md) that you identify with a <mark style="color:purple;">**label**</mark> may be <mark style="color:red;">**any**</mark>**&#x20;**<mark style="color:yellow;">**statement**</mark>."

📘 [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#labeled_statement)
{% endhint %}
{% endtab %}

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

* <mark style="color:yellow;">**flow control**</mark>
  * [continue](/web/js/grammar/statement/flow/jump/continue.md)
  * [break](/web/js/grammar/statement/flow/jump/break.md)
    {% endtab %}

{% tab title="📗 參考" %}

* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 5.5.1 Labeled Statements
  {% 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) ⟩[ label](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label) ⭐️
* [ ] [Loops and iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration) ⟩ [label statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#labeled_statement)
  {% endtab %}
  {% endtabs %}
