parseInt() method
I have an understanding that the parseInt() method returns an integer value based on the string passed to it. And when given a second parameter is passed to it as a number, it will return the integer value of string based on the radix of the second parameter (e.g parseInt('245', 8) will return the integer value of the string in base 8). While learning about the parseInt() method, I also learnt that you can convert a number to it's string literal in a particular radix using toString(radix) method. (e.g from the first example I gave above, toString(10) will convert the returned octal value of the parseInt() method to decimal). I came across an exercise that asks you to write a function to convert a binary (base 2) number to decimal (base 10). Now I know there are a number of ways of do this but with my understanding of parseInt() method I was able to write the code like this: function bin_to_dec(base2str) { var base10 = parseInt(base2str, 2).toString(10); return base10; } document.write(bin_to_dec('100')) //outputs 4 This is correct as the solution they gave was also written somewhat like this. However while I was viewing codes of other participants, I came across a code that was written like this: function ex2(bin) { return parseInt(bin, 2); } document.write(ex2('100')) //outputs 4 This is also correct but I am confused because from what I have understood, the parseInt() method should have converted the string to the radix of that specified in the second parameter, in this case base 2 (i.e. the output should have been in base 2 from what I understand). What am I getting wrong? I am a beginner in JavaScript programming.