What the hell does radix mean and do?

Have you actually looked up the word “radix”? The primary definition is what it means here, it isn’t a special JavaScript term, it just means “the base of a system of numeration”.

parseInt tries to convert a string containing a number to an integer. The radix argument tells the function what type of representation is being used in the string, because numbers can be represented in many different ways.

So 10011 is the number 19 written in binary. 23 is the number 19 written in octal. 19 is the number 19 written in decimal. 13 is the number 19 written in hexadecimal.

The number is the same but the characters used to represent it visually are not. The different useful types of representation are categorised by the number of numeric characters available. Binary has two available (0 and 1). Decimal has ten available (0,1,2,3,4,5,6,7,8,9). Hexadecimal has sixteen available (0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f).

So as an analogy, it is a similar concept w/r/t spoken languages: ship, bateau, Schiff, , корабль, Embarcacion – they all represent the concept of “ship”, they’re just written differently. Say you had written a JS function called “translateWordToEnglish”, it could take a string as the first argument and the language the string was written in for the second, just like parseInt does for numbers.

translateWordToEnglish("bateau", "fr")
translateWordToEnglish("корабль", "ru")
2 Likes