JS Coding Questions Logo
JS Coding Questions
#145💼 Interview💻 Code

What are js labels

Advertisement

728x90

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
1var i, j;
2
3loop1: for (i = 0; i < 3; i++) {
4  loop2: for (j = 0; j < 3; j++) {
5  if (i === j) {
6  continue loop1;
7  }
8  console.log("i = " + i + ", j = " + j);
9  }
10}
11
12// Output is:
13//   "i = 1, j = 0"
14//   "i = 2, j = 0"
15//   "i = 2, j = 1"

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 60

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
145of476