TIL Labels in Javascript
POSTED ON:
TAGS: javascript
The labeled
statement can be used with break or continue statements. It is prefixing a statement with an identifier which you can refer to.
Via the MDN
How does it work?
fireThisStatement: {
console.log("first");
break fireThisStatement;
console.log("second");
}
// > first
// -> undefined
TYou can use a label
to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.
In the example above, we identify a label
fireThisStatement. After that console.log('first');
executes and then we interrupt the execution.
Via WTF Javascript
Related TILs
Tagged: javascript