Get to know MDN better
The JavaScript exception "functions cannot be labelled" occurs when a function declaration has a label before it.
Function declarations are never supposed to be labeled, because labels should only apply to statements, not declarations. There's no way to actually jump to this label. However, due to some legacy JavaScript syntax rules, the error condition is a bit more complicated than necessary:
The error message may say something along the lines of "invalid place for a function declaration to appear", because when the parser sees a label, it expects a statement to follow, and a function declaration is not a statement. It depends on whether the error's perspective is that a label cannot be followed by a function, or that a function cannot be preceded by a label.
While it's possible that you actually expect the label to do something along the lines of being a jump target, usually you didn't intend for it to be a label. The most common case is you actually want it to be a property key in an object literal:
Here, {...} is actually not an object literal, but is instead the block body of the arrow function, so greet: becomes a label. To fix this, you need to wrap the object literal in parentheses:
You may also want to use the method syntax for object literals, which avoids this pitfall:
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.