JavaScript Number.parseInt() Method
The Number.parseInt() static method reads an integer from the start of a string, in a given base. It is identical to the global parseInt().
Description
The Number.parseInt() static method parses a string and returns an integer in the given radix. It's the same function as the global parseInt(). Always pass the radix, usually 10.
Using Number.parseInt() instead of the global function makes it clear that the code is working with numbers, and some style guides prefer it for that reason. It ignores leading white space, stops at the first invalid character, and returns NaN if no digits can be read.
Decimals are cut off rather than rounded, and numbers written in exponential notation are read only up to the e, so Number.parseInt('1e3') is 1. Use Math.round() or Math.trunc() on an actual number when you want to drop decimals.
Syntax
Number.parseInt(string)
Number.parseInt(string, radix)Parameters
- stringThe value to parse.
- radixOptional. The base, from 2 to 36.
Return Value
An integer, or NaN.
Example
Browser Support
The following information will show you the current browser support for the Number.parseInt() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





