Maximum base for parseInt ()?

The second parameter parseInt() defines the base from which the first parameter is processed. I played with some numbers and found out that I no longer get the correct answer if the base is more than 36:

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

Is there a limit? And why is it 36?

I used chrome when I ran tests

+7
source share
4 answers

36 is 10 + 26. There are 26 letters in the alphabet, plus 0-9. This is the maximum radius you can use.

+17
source

The ECMAScript specification indicates the maximum radius as 36.

  • There are 10 digits: (0-9)
  • There are 26 characters: (az)
 10 + 26 = 36 

It should also be mentioned that one could maintain a radius above 36 . The spectrum can be tuned to use case-sensitive characters for radix> 36, say, 37-62. Special characters can be used, such as accented characters and letters.

The reason this is not so is because it is ambiguous and not needed. Parsing algorithms for custom rexics should not be too complicated and can be written as needed.

Limiting the radius to 36 helps balance performance with the utility.

+9
source

This is 36 because the string representation uses 0-9 plus the alphabet for any extra digits. 10 + 26 = 36.

+3
source

Maximum 36, because the number of digits and characters of the standard alphabet has (0123456789abcdefghijklmnopqrstuvwxyz). If you are wondering about anything else like this, you can bookmark the official ECMAScript language specification , everything is there

+2
source

All Articles