JavaScript (ES2026) reference · Number Methods and Properties
JavaScript Number.parseInt() Method
Parse an integer from the start of a string in a given base (radix). Always pass the radix, usually 10.
JavaScript (ES2026) Since ES2015
Syntax
Number.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(Number.parseInt("42px", 10), Number.parseInt("ff", 16), Number.parseInt("101", 2));
Output
42 255 5
console.log(Number.parseInt("3.99", 10), Number.parseInt("abc", 10));
Output
3 NaN
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
int()· Python
Related
Number.parseFloat()· Parse a decimal number from the start of a string, ignoring trailing text. Same as the global parseFloat().number.toString()· Convert a number to a string, optionally in another base such as 2 (binary) or 16 (hexadecimal).parseInt()· Parse an integer from the start of a string in a given base. Always pass the radix, e.g. parseInt("08", 10).- JavaScript Numbers · tutorial
- JavaScript Type Conversion · tutorial