JSLint will throw the "'{a}' is not a label" error when it encounters a break or continue statement referencing a label that does not exist. In the following example we try to break out of a for loop to the example label:
This error is raised to highlight a JavaScript syntax error. It is not valid to reference an identifier that does not appear in the label set of the enclosing statement. This is stated in the ECMAScript 5 specification (section §12.7 and section §12.8):
A program is considered syntactically incorrect if...
- ...
- The program contains a break statement with the optional Identifier, where Identifier does not appear in the label set of an enclosing ... Statement.
In the snippet above, the for statement has not been explicitly labelled, and therefore there is no label in its label set with the identifier example. When the interpreter reaches the break statement a syntax error will be thrown. This can be avoided by either removing the identifier from the break statement:
Or adding a label with the correct identifer to the label set of the for statement: