JSLint says "missing radix parameter"

Mike Vierwind picture Mike Vierwind · Oct 19, 2011 · Viewed 305.2k times · Source

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?

Answer

Jayendra picture Jayendra · Oct 19, 2011

It always a good practice to pass radix with parseInt -

parseInt(string, radix)

For decimal -

parseInt(id.substring(id.length - 1), 10)

If the radix parameter is omitted, JavaScript assumes the following:

  • If the string begins with "0x", the radix is 16 (hexadecimal)
  • If the string begins with "0", the radix is 8 (octal). This feature is deprecated
  • If the string begins with any other value, the radix is 10 (decimal)

(Reference)