JS label statement

https://codepen.io/Onii-Sann/pen/mdvJVEe I'm trying to use label then call the label using continue and break statement without using loop statement, then it doesn't work and throw the runtime error, does the label statement only can be used over loop statement?
3 Replies
Jochem
Jochem13mo ago
That's correct, labels are only for break and continue Using goto statements (which is what you'd use for labels elsewhere in a different language) is generally considered bad practice and can lead to code that is incredibly difficult to read and debug
Abrar
AbrarOP13mo ago
Thanks for the explanation sir
ἔρως
ἔρως13mo ago
even for that, you might try other less performant methods that are more readable, like using .forEach since it is just a function, you can just return from it if you need to break out of all the loops, then yeah, the label might be the easiest method
Want results from more Discord servers?
Add your server