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

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

Syntax

Number.parseInt(string, radix)

Parameters

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

Return value

An integer or NaN.

Examples

Different basesTry it yourself
console.log(Number.parseInt("42px", 10), Number.parseInt("ff", 16), Number.parseInt("101", 2));

Output

42 255 5
Truncates decimals; NaN when nothing parsesTry it yourself
console.log(Number.parseInt("3.99", 10), Number.parseInt("abc", 10));

Output

3 NaN

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?