<script>
document.write(parseInt(15,16)) // Output 21, Hexadecimal Number system
document.write("<br>");
document.write(parseInt(15,8)) // Output 13, Octal Number system
document.write("<br>");
document.write(parseInt(5,2)) // Output NaN, Not a Binary Number system
document.write("<br>");
document.write(parseInt(101,2)) // Output 5, Binary Number system
document.write("<br>");
</script>
By using parseInt function we can convert strings to integer.
Without any value for Radix or if Radix = 0 then if input string starts with 0x or 0X then radix is considered as 16 ( hexadecimal number system )
Similarly if input string starts with 0 then radix is considered as 8 ( Octal number system )
In all other cases ( input string starting with any other value ) Radix is assumed as 10 ( decimal system ).
<script>
document.write(parseInt(0XA)) // Output 10 , Hexadecimal Number system
document.write("<br>");
document.write(parseInt(011)) // Output 9 , Octal Number system
document.write("<br>");
</script>
It is always better to specify Radix ( even for decimal number system )
Example of parseInt function
Here is a demo where inputs are used after passing through parseInt function. The output is then considered for calculation.
Enter some numbers with decimal values here.
Here is the code of this demo