The parseInt() function extracts an integer from a string.
-
The parseInt() function converts each character in the string to integer,
until it encounters a non-numerical value.
-
It returns NaN if the string does not start with
a numerical value, +, -, or 0X.
In the example given above,
the parseInt() function converts the first set of numerical characters,
i.e., "123" to integer.
Since the next character "p" is a non-numerical,
the function stops execution
and
returns 123.
In the example given above,
the parseInt() function converts the first set of numerical characters,
i.e., "12" to integer.
Since the next character "." is a non-numerical,
the function stops execution
and
returns 12.
In the above example,
the parseInt() function returns NaN
because it starts with the character "R",
which is not a number.