Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 770
user_78361084 Avatar asked Sep 29 '12 03:09

user_78361084


2 Answers

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.

like image 148
elclanrs Avatar answered Sep 20 '22 20:09

elclanrs


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.
like image 20
jeff Avatar answered Sep 19 '22 20:09

jeff