Skip to main content
InterviewHubPRO
Section Overview
Q149

Question 149 of 536

Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

28%
JavaScript & V8 Internals (536 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

What are js labels

junior LevelCode ExampleHTTP & REST APIs

The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,

javascript
  var i, j;

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

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