The parseInt() function parses a string argument and returns an integer of the specified radix (default 10). In case the string starts with a valid number and ends with non numeric characters, parseInt still returns the parsed Integer by parsing upto the first non-digit.
parseInt(string, radix);
Example – parseInt returning valid number
<script> document.write(parseInt("37") + "<br>"); document.write(parseInt("-37") + "<br>"); document.write(parseInt("+37") + "<br>"); document.write(parseInt(" 37") + "<br>"); document.write(parseInt("37abc") + "<br>"); document.write(parseInt("37.37") + "<br>"); </script>
Example – parseInt returning NaN
<script> document.write(parseInt("abc") + "<br>"); document.write(parseInt("") + "<br>"); </script>