Get code to resolve the RangeError: toString() radix argument must be between 2 and 36. Radix in parseInt()
or toString()
cannot be less than 2 and greater than 36.
This is because a number representation like binary, decimal, octal, hexadecimal etc. can contain only alphanumeric characters. We have 0-9A-Z characters which are 10 numbers and 26 alphabets. So, at most we can have 36 characters in a number system. That’s why it can’t be greater than 36.
It can’t be less than 2 like 1 because then we will left with only one character – 0. Any number made up of 0 will always be 0. So, that’s not helpful.
Code Example –
RangeError –
(49).toString(0);
(49).toString(1);
(49).toString(37);
(49).toString(135);
// You cannot use a string like this for formatting:
(16088080).toString('MM-dd-yyyy');
Correct Code –
(49).toString(2); // "110001" (binary)
(34).toString(8); // "42" (octal)
(0x23).toString(10); // "35" (decimal)
(147365).toString(16) // "23fa5" (hexadecimal)
Source: MDN