Can someone please explain why we are getting following results in JavaScript?
parseInt ( 'a' , 24 ) === 24 ;
>false
parseInt ( 'a' , 34 ) === 24 ;
>false
parseInt ( 'o' , 34 ) === 24 ;
>true
The second argument to parseInt(string, radix);
is a integer between 2 and 36 that represents the radix of the first argument string.
The return value of parseInt(string, radix);
will be the decimal integer representation of the first argument taken as a number in the specified radix.
Now,keeping that in mind if you convert them :
Input Output
a (base-24) 10 (base-10)
a (base-34) 10 (base-10)
o (base-34) 24 (base-10)
So, as you can see in third case it comes out to be 24 and bingo! there you go the condition is true.
You can use any online tool to convert from one number system to another like I used this one :
Hope this Helps!