MDN recommends NOT to use labels in Javascript, and instead use exceptions or functions. But turns out labels are the fastest, closely followed by named functions.
Test case: Run two nested loops. The inner loop needs to continue
the
outer loop upon some condition.
Tests:
- Using named loops with labels.
- Using an anonymous function.
- Using a named function.
- Using exceptions.
Results:
$ time node labels.js
real 0m0.138s
user 0m0.130s
sys 0m0.008s
###################
$ time node anon_func.js
real 0m0.631s
user 0m0.623s
sys 0m0.011s
###################
$ time node named_func.js
real 0m0.163s
user 0m0.155s
sys 0m0.007s
###################
$ time node throw.js
real 0m1.868s
user 0m1.860s
sys 0m0.018s
http://stackoverflow.com/questions/4906762/is-using-labels-in-javascript-bad-practice
That text was removed from MDN in May 2015, with these comments in the revision history: "Removing recommandation not supported by clear evidence." "Clearing technical review. I think it is true that there is no need for the big red banner that discourages labels. Havent found anything that says differently." –