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

雨燕双飞 提交于 2020-07-04 08:50:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!