Skip to content
JS
JavaScript error

SyntaxError

The JavaScript exception "functions cannot be labelled" occurs when a function declaration has a label before it.

Reference entryJavaScriptFetched
SyntaxError: In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement. (V8-based)
As listed by MDN Web Docs
SyntaxError: In strict mode code, functions can only be declared at top level or inside a block. (V8-based)
As listed by MDN Web Docs
SyntaxError: Generators can only be declared at the top level or inside a block. (V8-based)
As listed by MDN Web Docs
SyntaxError: Async functions can only be declared at the top level or inside a block. (V8-based)
As listed by MDN Web Docs
SyntaxError: functions can only be labelled inside blocks (Firefox)
As listed by MDN Web Docs
SyntaxError: functions cannot be labelled (Firefox)
As listed by MDN Web Docs
SyntaxError: generator functions cannot be labelled (Firefox)
As listed by MDN Web Docs
SyntaxError: async function declarations can't appear in single-statement context (Firefox)
As listed by MDN Web Docs
SyntaxError: Unexpected keyword 'function'. Function declarations are only allowed inside block statements or at the top level of a program. (Safari)
As listed by MDN Web Docs
SyntaxError: Function declarations are only allowed inside blocks or switch statements in strict mode. (Safari)
As listed by MDN Web Docs
SyntaxError: Unexpected token '*'. Cannot use generator function declaration in single-statement context. (Safari)
As listed by MDN Web Docs
SyntaxError: Unexpected keyword 'function'. Cannot use async function declaration in single-statement context. (Safari)
As listed by MDN Web Docs
Category
SyntaxError
Severity
error
Runtime
both
or press Cmd/Ctrl + Enter. The text is only sent to this site to match it.
Source: MDN Web Docs. Data fetched 2026-09-25T01:48:37.273Z.