Question about parseInt Function with a Radix

function convertToInteger(str) {
return parseInt(str, 2);
}

convertToInteger("10011");

The radix variable can be anything between 2 & 36 ? is that correct ? if so then why couldnt it be higher then that?

That is just the way the API was designed.

Specs: 19.2.5 parseInt ( string, radix )

  1. If R ≠ 0, then
    a. If R < 2 or R > 36, return NaN.

(14). Let mathInt be the integer value that is represented by Z in radix-R notation, using the letters A-Z and a-z for digits with values 10 through 35. (However, if R is 10 and Z contains more than 20 significant digits, every significant digit after the 20th may be replaced by a 0 digit, at the option of the implementation; and if R is not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation-approximated integer representing the integer value denoted by Z in radix-R notation.)

If you are asking why it was designed that way, as far as I can tell, 26 letters in the alphabet, plus 0-9 digits = 36

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.