Fork me on GitHub

JSLint Error Explanations

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


Unexpected dangling '_' in '{a}'

When do I get this error?

JSLint will throw the "Unexpected dangling '_' in '{a}'" error when it encounters an identifier that begins or ends with the underscore character. JSHint will throw this error in the same situation, but only if the nomen option is set to true. In the following example we use several such identifiers:

Why do I get this error?

This error is raised to highlight a lack of convention. Your code will run without error if you do not change it, but could be confusing to other developers, and could also indicate a lack of understanding of the language.

Identifiers prefixed with the underscore character are often used to indicate a private variable. Since JavaScript doesn't have a real notion of "private", this can be misleading.

If you're using JSLint, you can fix the error by setting the nomen (short for nomenclature) option to true. Conversely, if you're using JSHint, you can simply remove the same option:

Alternatively, you can simply remove the underscore character from the start or end of your identifiers (note that use of this character elsewhere in identifiers is accepted):


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