[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/label [Back]  [Original]

label - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

label

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

break continue . .

: . .

In this article

js
label:
  statement;
label

JavaScript .

statement

. break , continue .

, break continue .

JavaScript goto . break continue .

strict mode "let" . SyntaxError . (let .)

for continue

js
var i, j;

loop1: for (i = 0; i < 3; i++) {
  // for "loop1"  .
  loop2: for (j = 0; j < 3; j++) {
    // for "loop2"  .
    if (i === 1 && j === 1) {
      continue loop1;
    }
    console.log("i = " + i + ", j = " + j);
  }
}

//  :
//   "i = 0, j = 0"
//   "i = 0, j = 1"
//   "i = 0, j = 2"
//   "i = 1, j = 0"
//   "i = 2, j = 0"
//   "i = 2, j = 1"
//   "i = 2, j = 2"
//       : "i = 1, j = 1", "i = 1, j = 2"

continue

items, tests tests items .

js
var itemsPassed = 0;
var i, j;

top: for (i = 0; i < items.length; i++) {
  for (j = 0; j < tests.length; j++) {
    if (!tests[j].pass(items[i])) {
      continue top;
    }
  }

  itemsPassed++;
}

for break

js
var i, j;

loop1: for (i = 0; i < 3; i++) {
  //The first for statement is labeled "loop1"
  loop2: for (j = 0; j < 3; j++) {
    //The second for statement is labeled "loop2"
    if (i === 1 && j === 1) {
      break loop1;
    }
    console.log("i = " + i + ", j = " + j);
  }
}

// Output is:
//   "i = 0, j = 0"
//   "i = 0, j = 1"
//   "i = 0, j = 2"
//   "i = 1, j = 0"
// Notice the difference with the previous continue example

break

items, tests , items tests .

js
var allPass = true;
var i, j;

top: for (i = 0; items.length; i++)
  for (j = 0; j < tests.length; i++)
    if (!tests[j].pass(items[i])) {
      allPass = false;
      break top;
    }

break

, break .

js
foo: {
  console.log("face");
  break foo;
  console.log("this will not be executed");
}
console.log("swap");

//   :

// "face"
// "swap

ECMAScript 2015, web compatibility annex of the specification non-strict .

js
L: function F() {}

strict mode SyntaxError .

js
"use strict";
L: function F() {}
// SyntaxError: functions cannot be labelled

Generator functions strict code non-strict code .

js
L: function* F() {}
// SyntaxError: generator functions cannot be labelled

Specification
ECMAScript 2027 LanguageSpecification
# sec-labelled-statements


Web Proxy Viewer  |  New URL  |  Original Page