Labels are common technique across the programming world and JavaScript is no exception.

The labels or label statements are often used with the loops, and together they offer powerful programming tools.

The downside of labels is that sometimes they make troubleshooting more difficult, especially if they are used with nested loops; therefore special attention is needed in applying labels.

This is how labels are created:

label1: statement;



In reality that might look something like this:

for (var i = 0; i <= 15; i++) {

   if ((i > 3) && (i < 13)) break middle;

   else break edge;


middle: // label 1

document.write("The shoe size is in the middle range.");

edge: // label 2

document.write("The shoe size is either very small or very big!");


›› go to examples ››