jslint-error-explanations
jslint-error-explanations copied to clipboard
Explain Unexpected '1'
trafficstars
When converting a string like '9.59' to a number I have always used the syntax: var a = '9.59'; a = a * 1;
JSLint seems to find this method odd and destructive. I thought my method was fairly standard and straight forward. It also happens to be the fastest to execute vs any other method like parseInt or parseFloat or Math.floor
Use a plus can easily change convert string to number.
var a = '9.59';
a = +a;
But change a variable type is not good practice. Assign the result number to another variable is much better.
And I think * 1 is a meaning less operation.
The formula means nothing will change.
So JSLint warns.