📜label

JSstatementother ⟩ label

(statement)

prefixes a statement with an identifier which you can refer to.

<label> : <statement>        // syntax

label is only used by break / continue.

( nested loop)

labeled statement is needed

  • when you want to skip to the next iteration of an outer loop that is not the nearest enclosing loop.

  • when you want to break out of a statement that is not the nearest enclosing loop / switch.

The namespace for labels is different than the namespace for variable(s) and function(s), the same identifier can be used as label / variable or function name.

"the statement that you identify with a label may be any statement."

📘 MDN

Last updated