JavaScript (ES2026) reference · JSON and Global Functions

JavaScript parseInt() Function

Parse an integer from the start of a string in a given base. Always pass the radix, e.g. parseInt("08", 10).

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

parseInt(string, radix)

Parameters

ParameterDescription
string The text to parse.
radix optional Base from 2 to 36.

Return value

An integer or NaN.

Examples

Parse integersTry it yourself
console.log(parseInt("42", 10), parseInt("42.9", 10), parseInt("  7 apples", 10));

Output

42 42 7
Hex prefixes and empty inputTry it yourself
console.log(parseInt("0x1A"), parseInt("1A", 16), parseInt(" ", 10));

Output

26 26 NaN

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?