Fork me on GitHub

JSLint Error Explanations

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


Unclosed comment

When do I get this error?

JSLint and JSHint will throw the "Unclosed comment" error when they encounter a multiline comment that does not end with the characters */. Here's an example:

Why do I get this error?

This error is raised to highlight a JavaScript syntax error. The ECMAScript 5 specification lists the following grammar for multiline comments (section §7.4):

MultiLineComment ::
    /* MultiLineCommentCharsopt */

We can see from the above quote that multiline comments must end with the */ characters. If you have an unclosed multiline comment a syntax error will be thrown when the interpreter reaches the end of the file. Here's the above snippet once more, except we've closed the comment this time:

JSHint bug alert!

As you may have noticed if you have switched one of the example above to use JSHint instead of JSLint, a large number of the same error appear to get generated for the first unclosed comment, to the point where the parser gives up and tells you that there are too many errors. Fixed as of JSHint 1.0.0.

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. Since this message relates to a fatal syntax error you cannot disable it.


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