re: Did you know that JavaScript has had labels since ES3?!? VIEW POST


Labels are used together with goto statements (continue in JavaScript case), which encourage really unpredictable coding techniques and thus bad style that should be avoided. Having execution order controlling constructions like if statement and loops must be enough; once you define a loop there's no way to enter this loop skipping the initialization phase, the same is true for an if or else clause. Seeing a label in the source code cannot help you understand what's going on because you could possibly jump to this point from anywhere within the same file, under any circumstances.

On the other hand, the ability to stop the execution of not only an inner loop but also of any of outside ones using break <LABEL> seems much more reasonable at first glance. However, I would assume if you have a need to do that something might be really wrong with the algorithm you use - and it's better to revise it instead of using labeled breaks.

Code of Conduct Report abuse