This is a strange one, and took  some tracking down. Most attempts to bring about this message merely yielded another similar message: A trailing decimal point can be confused with a dot ‘{a}’.

Eventually I stumbled across it. So, what do you expect the following to yield?  (Readers should note that the space between the ’2′  and the ‘.x’ is intentional):

alert(2 .x);

Well, the answer is ‘undefined’.

Eh?

Things only appear to get stranger. Try this:

alert(2 .valueOf());

The alert here pops up with ’2′. Okay, so clearly it’s another way of writing the following…

alert(2.valueOf());

Right? Wrong! This merely yields a syntax error.

What’s going on here is best explained over at Stackoverflow: What’s going on with this rather peculiar JavaScript syntax?

A floating-point numeric constant must not have embedded spaces. Thus, ’2 .x’ is an expression calling for the constant ’2′ to be promoted to a Number object, and then the property called ‘x’ is examined. There isn’t one, of course, so the value is ’undefined’.

I can see why JSLint complains about it. The convention is so arcane that it’s probably not what the developer intended, and if they did then they really ought to have known better!

A Guide To JSLint Messages

This article is one of a series on the error and warning messages produced by JSLint.

, , ,
Trackback

only 1 comment untill now

  1. [...] be within ‘<{b}>’. A constructor name should start with an uppercase letter. A dot following a number can be confused with a decimal point. A leading decimal point can be confused with a dot ‘.{a}’. A trailing decimal point can [...]

Add your comment now