Favorites

JavaScript parseInt() Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
parseInt()
JavaScript Global functionThis function is supported by all modern browsers.
Updated 28th November 2026

The parseInt() function reads a string and returns the whole number at its start, in the given base. It stops at the first character that isn't a digit.

Description

The parseInt() global function parses a string and returns an integer in the specified base (radix). It reads digits from the start of the string and stops at the first character that isn't valid, so parseInt('42px') returns 42. If no digits can be read, it returns NaN.

Always pass the radix, usually 10. Without it, strings starting with 0x are read as hexadecimal, which can lead to surprising results with user input. Decimals are cut off rather than rounded: parseInt('3.9') is 3.

To convert a whole string to a number and get NaN if any of it is invalid, use Number() instead. parseInt() is also available as Number.parseInt().

Syntax

parseInt(string)
parseInt(string, radix)

Parameters

  • stringThe value to parse. It is converted to a string first, and leading white space is ignored.
  • radixOptional. A number from 2 to 36 giving the base of the number, such as 10 for decimal or 16 for hexadecimal.

Return Value

An integer parsed from the start of the string, or NaN if the first non-space character can't be turned into a number.

Example

console.log(parseInt('42', 10));
console.log(parseInt('42px', 10));    // stops at "p"
console.log(parseInt('3.9', 10));     // no rounding
console.log(parseInt('ff', 16));      // hexadecimal
console.log(parseInt('hello', 10));
console.log(Number('42px'));          // compare

Browser Support

The following information will show you the current browser support for the parseInt() function. Hover over a browser icon to see the version that first introduced support for this function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee