I ran JSLint on this JavaScript code and it said:
Problem at line 32 character 30: Missing radix parameter.
This is the code in question:
imageIndex = parseInt(id.substring(id.length - 1))-1;
What is wrong here?
I ran JSLint on this JavaScript code and it said:
Problem at line 32 character 30: Missing radix parameter.
This is the code in question:
imageIndex = parseInt(id.substring(id.length - 1))-1;
What is wrong here?
I'm not properly answering the question but, I think it makes sense to clear why we should specify the radix.
On MDN documentation we can read that:
If radix is undefined or 0 (or absent), JavaScript assumes the following:
Source: MDN parseInt()
To avoid this warning, instead of using:
You may replace it by:
Note that parseInt and Number have different behaviors, but in some cases, one can replace the other.
You can also simply add this line right above your parseInt line:
This will disable eslint check for the next line. Use this if you only need to skip one or two lines.
I solved it with just using the +foo, to convert the string.
Keep in mind it's not great for readability (dirty fix).
It always a good practice to pass radix with parseInt -
For decimal -
If the radix parameter is omitted, JavaScript assumes the following:
(Reference)
Adding the following on top of your JS file will tell JSHint to supress the radix warning:
See also: http://jshint.com/docs/#options