问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/12649748/jslint-error-a-leading-decimal-point-can-be-confused-with-a-dot