The parseInt()
function is a built-in function in JavaScript which allows users to convert a string to an integer value.
The basic syntax of the function is:
The parseInt()
function takes the following parameters as input:
Radix is an optional parameter. In case it is not mentioned, the following assumptions are made:
If the function parses the string successfully, the integer value is returned. In case the string cannot be converted to an integer value, NaN
is returned.
Note: In case the string starts with a numeric character but is followed by an alpha-numeric character, the string is parsed until the occurrence of the first alphanumeric character
Let’s look at some examples to understand further how to use the parseInt()
function:
Free Resources