Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum base for parseInt()?

The second parameter of parseInt() defines the base to which the first parameter is parsed to. I have been playing around with some numbers and found out that I do not get a correct answer anymore if the base is larger than 36:

parseInt("1", 36);
// -> 1

parseInt("1", 37);
// -> NaN

Is there a limit? And why is it 36?

I was using chrome when I ran my tests

like image 634
Amberlamps Avatar asked Nov 05 '12 15:11

Amberlamps


People also ask

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).

What is parseInt () function?

The parseInt method parses a value as a string and returns the first integer. 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.

What is the default radix for parseInt?

By default radix is 10 (decimal).

What is the second parameter of parseInt?

parseInt takes two parameters, the second one is optional. String and Radix. String is the value to parse. If the value provided is not a string it will convert it to a string.


1 Answers

36 is 10 + 26. There are 26 letters in the alphabet, plus 0-9. That's the maximum radix you can use.

like image 157
gilm Avatar answered Oct 17 '22 08:10

gilm