You are currently viewing Integer parseint() Function in JavaScript

Integer parseint() Function in JavaScript

Integer parseint Javascript

Learn what is integer parseint in javascript and how to use it.

parseInt() function converts a given value to an integer number, if not possible to convert then returns the NaN value. NaN means not a number.

If the given value is of integer type, then it returns the number as it is.

document.write(parseInt(24)); //24

If the given value is of float type, then it discards the floating part and returns the integer part of the number.

document.write(parseInt(3.4)); //3
document.write(parseInt(1.6 + 1.6)); //3

If the given value is of string type, then it tries to extract and return the beginning integer part.
If the string passed to the parseInt() function does not begin with an integer then it returns the NaN value. All text enclosed in double quotes will be treated as a String by the browser.


document.write(parseInt("3")); //3
document.write(parseInt("25")); //25
document.write(parseInt("3sometext")); //3
document.write(parseInt("3" + "5")); //35

Here, the given string is not possible to convert integer, so it returns NaN.

document.write(parseInt("sometext24")); //NaN

Leave a Reply