Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint says "missing radix parameter"

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?

like image 201
Mike Vierwind Avatar asked Oct 19 '11 09:10

Mike Vierwind


People also ask

What is missing radix parameter?

A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10. If the value begins with "0x", JavaScript assumes radix 16.

What is radix parameter in parseInt?

JavaScript parseInt() Function The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.

What is parseInt base?

The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).


1 Answers

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)

like image 90
Jayendra Avatar answered Oct 02 '22 13:10

Jayendra