Number

Number.parseInt

Parses a string argument and returns an integer of the specified radix

Syntax

JavaScript
Number.parseInt(string, radix?)

Parameters

ParameterTypeDescription
stringstringThe value to parse
radixnumberAn integer between 2 and 36 representing the base

Return Value

An integer parsed from the given string, or NaN

Examples

Basic Usage
console.log(Number.parseInt('42')); // 42
console.log(Number.parseInt('0xFF', 16)); // 255
Practical Example
console.log(Number.parseInt('101', 2)); // 5 (binary)
console.log(Number.parseInt('77', 8)); // 63 (octal)
Advanced Usage
console.log(Number.parseInt('42px')); // 42
console.log(Number.parseInt('hello')); // NaN

Understanding 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

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.