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
Syntax
parseInt(string, radix)
Parameters
| Parameter | Description |
|---|---|
string |
The text to parse. |
radix optional |
Base from 2 to 36. |
Return value
An integer or NaN.
Examples
console.log(parseInt("42", 10), parseInt("42.9", 10), parseInt(" 7 apples", 10));
Output
42 42 7
console.log(parseInt("0x1A"), parseInt("1A", 16), parseInt(" ", 10));
Output
26 26 NaN
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
int()· Python
Related
Number.parseInt()· Parse an integer from the start of a string in a given base (radix). Always pass the radix, usually 10.parseFloat()· Parse a decimal number from the start of a string, stopping at the first character that can't be part of it.- JavaScript Type Conversion · tutorial