Why do labels exist in javascript?
var i = 0; usefulLabel://why do I exist? while(i <= 10){ document.writeln(i); i++; if(i > 5) break;// usefulLabel; }
The above code does not need a shortcut at all (it works with or without the name of the marked shortcut). And given that Douglas Crockford did not completely condemn them:
Shortcuts
Signs of operators are optional. Only these statements should be labeled: while, do, for, switch.
Are they ever considered good practice for implementation? For me, these things are terribly close to the infamous goto instruction in some languages.
source share