Fork me on GitHub

JSLint Error Explanations

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


Expected a string and instead saw '{a}'

When do I get this error?

JSLint (since late 2012) will throw the "Expected a string and instead saw '{a}'" error when it encounters a comparison operator in which one of the operands is a typeof expression and the other operand is not a string literal. It will raise the same error when it encounters an unquoted JSON property. In the following example we attempt to compare the result of the typeof operator with the value of a variable:

And in the next example we have an unquoted JSON property:

Why do I get this error?

In the typeof case, this error is raised to highlight a potentially confusing piece of code. The code is perfectly valid and will work in all cases, but could be difficult to read or understand at first glance. If you want to store possible typeof values instead of comparing to literals, you can safely ignore this warning.

However, it is a simple fix. Just replace the variable reference with the appropriate string literal:

In the JSON case, this error is raised to highlight a syntax error. The JSON specification states that property identifiers must be wrapped in double quotes:


comments powered by Disqus