Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!

'{a}' is not a label

When do I get this error?

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:

Why do I get this error?

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:

James Allardice

This article was written by James Allardice, an enthusiastic young JavaScript developer at Global Personals (we're looking for developers so please apply). He is passionate about writing clean, maintainable JavaScript and uses JSHint every day to help achieve this.

You can follow him on Twitter, fork him on GitHub and find him on Google+.

Proceeds generated by this site are donated to help advance other open source projects

comments powered by Disqus