16

I'm using jslint.com to validate some functions and came across the error:

"A leading decimal point can be confused with a dot"

The line which triggered the error is as follows:

if ( myvar = .95 ){

How do I correct it?

bozdoz
  • 12,550
  • 7
  • 67
  • 96
user_78361084
  • 3,538
  • 22
  • 85
  • 147
  • 10
    why is this downvoted? I may be a newb but doesn't mean it was a stupid question – user_78361084 Sep 29 '12 at 04:04
  • 7
    this really should not have been closed, this is a reasonable question about how to correct a jslint issue, and the top answer explains it perfectly. – NateDSaint Jan 07 '13 at 17:28
  • 2
    I agree. This question is just fine. Stack overflow should be accessible to all skill levels, just because this is a simple questions doesn't invalidate it by any means. – dudewad Sep 17 '14 at 19:51

2 Answers2

19

Easy, put a zero before the dot. I guess JSLint complains because the dot is also used for object properties so it can be confused. Plus you're missing an equals, but in JS is recommended to use triple equals:

if (myvar === 0.95) { ... }

Now JSLint won't complain anymore.

elclanrs
  • 92,861
  • 21
  • 134
  • 171
8

That's not a real Javascript error. Javascript will work fine without the leading 0. However, to prevent JSLint from showing that error, just add the leading 0:

if ( myvar = 0.95 ){

It's clearer, but not actually necessary.


And are you sure you're not trying to use two equals signs, as in ==? The = operator is for assignment, while the == operator is for comparison.
jeff
  • 8,300
  • 2
  • 31
  • 43
  • 1
    @Mr.Gaga - I know. I was just making it clear that that error was from JSLint and wouldn't generate an actual error in Javascript. – jeff Sep 29 '12 at 04:36