Fork me on GitHub

JSLint Error Explanations

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


Expected exactly one space between '{a}' and '{b}'

When do I get this error?

JSLint will throw the "Expected exactly one space between '{a}' and '{b}'" error when it encounters a number of spaces that is not equal to one in the following situations (there are numerous other examples that can cause this error, but these are some of the common ones):

  • Between any keyword (such as if, for or while) and its associated opening parenthesis:
  • Between the function keyword and its associated opening parenthesis, when the function is parsed as an expression (but not when it's parsed as a function declaration):
  • Between a closing parenthesis and its associated opening curly brace (such as in a function statement, if statement, switch statement etc):

Why do I get this error?

This error is raised to highlight a lack of convention and a possibly sloppy coding style. Your code will run without error if you do not change it, but may contravene best practices and look messy to other developers.

If you are happy with your coding style, you can tell JSLint to ignore whitespace (or the lack of whitespace) by setting the white option to true:

However, if you are using JSLint to enforce a consistent style, you will probably want to listen to what the error tells you, and just make sure you always use the correct whitespace:


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