Number.parseInt
Parses a string argument and returns an integer of the specified radix
Syntax
Number.parseInt(string, radix?)Parameters
| Parameter | Type | Description |
|---|---|---|
| string | string | The value to parse |
| radix | number | An integer between 2 and 36 representing the base |
Return Value
An integer parsed from the given string, or NaN
Examples
console.log(Number.parseInt('42')); // 42
console.log(Number.parseInt('0xFF', 16)); // 255console.log(Number.parseInt('101', 2)); // 5 (binary)
console.log(Number.parseInt('77', 8)); // 63 (octal)console.log(Number.parseInt('42px')); // 42
console.log(Number.parseInt('hello')); // NaNUnderstanding Number.parseInt
The Number.parseInt method in JavaScript parses a string argument and returns an integer of the specified radix. It belongs to the Number object and is one of the most widely used methods for working with number values in modern JavaScript and TypeScript applications.
The method signature is Number.parseInt(string, radix?). It accepts 2 parameters: string, radix. When called, it returns an integer parsed from the given string, or nan. Understanding when and how to use parseInt() helps you write more expressive, readable code.
Common use cases for Number.parseInt include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like number-parsefloat, number-isnan, number-isfinite, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Number.parseInt is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Number.parseFloatParses an argument and returns a floating-point number
Number.isNaNDetermines whether the passed value is NaN and its type is Number, providing a more robust version of the original global isNaN()
Number.isFiniteDetermines whether the passed value is a finite number — not Infinity, -Infinity, or NaN
More Number Methods
Other methods in the Number object
Related Tools
More Number Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.