Maximus Maximus - 1 year ago 87
Javascript Question

What the purpose of Labeled function declarations

I've recently come across

Labeled function declarations
. There is not much said about them on MDN website:

Starting with ECMAScript 2015, labeled function declarations are now
standardized for non-strict code in the web compatibility annex of the

L: function F() {}

The standard doesn't add much details either and there's nothing on the web as well.

Has anyone used them? What's the purpose of them? Any information is appreciated.

Answer Source

As far as I could gather, the only purpose seems to be support for bad code floating on the web. They cannot be referenced, and are completely useless.

Brandon Eich, 2012:

People tend to make unnecessary labels, especially in event handlers where javascript: at the front of the HTML attribute value has been seen in the wild. Couple that with a function expression that is not parenthesized, but possibly immediately invoked, and you have real trouble.

The fact that they are useless grammatical relics is the reason why they were gotten rid of.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download