JSLint and JSHint will throw the "Unclosed string" error when they encounter a string that is not closed at the next line break, or at the end of the program. In this first example, we accidentally forget to close our string:
In the next example, we want our string to include a backslash character. The string appears to be closed but actually isn't, due to the backslash character escaping the closing quote:
And this final example, which is only valid in ECMAScript 5-supporting environments, features a string that has not closed by the end of the program (the previous two examples failed at the first line break):
" DoubleStringCharactersopt "
' SingleStringCharactersopt '
To fix the error, simply close any unclosed strings:
The second example above failed because the backslash character was escaping the closing quote, turning it into a literal character rather than a syntactic structure. To include a backslash in a string, you need to escape the backslash itself:
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.