What's the point of using shortcuts in javascript (shortcut: here) foreign keys?

What is the point of using shortcuts in javascript (shortcut: here) external switches?

+5
source share
2 answers

You can use them as goto statements on breakand continue, although admittedly you rarely see this in practice. You can find some examples here.

Here is a quick one:

myLabel:
for(var i=0; i<10; i++) {
  if(i==0) continue myLabel; //start over for some reason
}    
+4
source

They are also useful in loops:

var x, y;

outer: for (x = 0; x < 10; ++x) {
    for (y = 0; y < 10; ++y) {
       if (checkSomething(x, y)) {
           break outer;
       }
    }
}

... which breaks out of both loops if it checkSomethingreturns true.

, , . , , goto ( JavaScript).

+3

All Articles