Fork me on GitHub

JSLint Error Explanations

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


A leading decimal point can be confused with a dot: '{a}'

When do I get this error?

JSLint (prior to July 2013) and JSHint will throw the "A leading decimal point can be confused with a dot: '{a}'" error when they encounter a numeric literal preceded by a . character which itself is not preceded by a decimal integer literal. Here's an example in which we attempt to assign the value 0.5 to the variable x:

Why do I get this error?

This error is raised to highlight a potentially confusing piece of code. Your code will run without error if you do not address this issue but it could be confusing to other developers.

The ECMAScript standard states that it is syntactically valid for a numeric literal to begin with a . character (ES5 Annex 1):

DecimalLiteral ::
    DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt
    . DecimalDigits ExponentPartopt
    DecimalIntegerLiteral ExponentPartopt

The second production in the grammar quoted above shows the situation we encounter in the example at the top of this page. However, since the . character is ambiguous (it's also commonly seen in use as a "member operator", to access a property of an object), JSLint and JSHint prefer the explicit first production from the above grammar, just to make your code easier to understand.

To fix this error, simply prepend a 0 to your number:

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W008. This means you can tell JSHint to not issue this warning with the /*jshint -W008 */ directive.


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