Example of Javascript Label

We can use javascript label to shift control to a certain code block.

Here is and example:

function forLoopAndLabels() {
  levelOne:
  for(let i = 0; i < 5; i++) {
    levelTwo:
    for(let j = 0; j < 5; j++) {
      if(i === j) {
        continue levelOne;
      }
      console.log(`Level 1: ${i}, Level 2: ${j}`);
    }
  }
}
Level 1: 1, Level 2: 0
Level 1: 2, Level 2: 0
Level 1: 2, Level 2: 1
Level 1: 3, Level 2: 0
Level 1: 3, Level 2: 1
Level 1: 3, Level 2: 2
Level 1: 4, Level 2: 0
Level 1: 4, Level 2: 1
Level 1: 4, Level 2: 2
Level 1: 4, Level 2: 3