In this tutorial, you will learn how to use the JavaScript break statement to control the execution of code in a loop.

Before discussing the break statement, let’s talk about the label statement first.

The label statement

In JavaScript, you can label a statement for later use. The following illustrates the syntax of the label statement:

label: statement;

The label can be any valid identifier.

The following example labels the loop using the outer label.

outer: for (let i = 0; i < 5; i++) {
    console.log(i);
}

You can reference the label by using the break or continue statement. Typically, you use the label with nested loop such as for, do-while, and while loop.

#javascript #programming #developer #web-development

JavaScript Control Flow - JavaScript Break Statement
1.75 GEEK