JavaScript Number.parseInt() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Number.parseInt(string, radix) reads a string and returns an integer. Optional radix (2–36) sets the numeric base. It skips leading whitespace, stops at the first invalid digit for that base, and is the same function as global parseInt.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call Number.parseInt. Start with this line.

JavaScript
Number.parseInt(string, radix)
CallWhat it does
Number.parseInt(string, radix)Primary signature.
Number.parseInt(...)Call with the arguments your case needs.

Built into JavaScript. Call Number.parseInt(...) on the Number constructor — no import required.

Library declarations
JavaScript
Number.parseInt(string, radix)

Parameters

ParameterDescription
stringRequired. Value to parse (coerced to string)

Return Value

Return ValueDescription
*Integer number, or NaN

JavaScript Examples

Example 1 — Decimal Parsing and Trailing Junk

Always pass radix 10. Junk after digits is ignored.

JavaScript
console.log(Number.parseInt("42", 10));     // 42
console.log(Number.parseInt("42px", 10));   // 42
console.log(Number.parseInt("15.9", 10));   // 15
console.log(Number("42px"));                // NaN
Try It Yourself

How It Works

  1. Explicit base. , 10 makes decimal parsing unambiguous.
  2. Stop at junk. After 42, the p ends the parse — result stays 42.
  3. Decimals truncate. The . is not a decimal digit in base 10 → stops at 15.
  4. Number is strict. Number("42px") needs the whole string valid → NaN.

Example 2 — Binary and Hexadecimal Radix

Change the base to parse binary or hex digit strings.

JavaScript
console.log(Number.parseInt("1010", 2));   // 10
console.log(Number.parseInt("ff", 16));    // 255
console.log(Number.parseInt("0xF", 16));   // 15
console.log(Number.parseInt("Z", 36));     // 35
Try It Yourself

How It Works

  1. Binary. "1010" in base 2 is eight + two → 10.
  2. Hex letters. f is 15; "ff" is 15×16 + 15 → 255.
  3. 0x prefix. With radix 16, a leading 0x is allowed and skipped.
  4. Base 36. Digits can use 0–9 and a–z; Z is 35.

Example 3 — Failed Parse Returns NaN

If no valid digit starts the string for that radix, the result is NaN.

JavaScript
console.log(Number.parseInt("hello", 10));  // NaN
console.log(Number.parseInt("", 10));       // NaN
console.log(Number.isNaN(Number.parseInt("hello", 10))); // true
console.log(Number.parseInt("15.9", 10));   // 15 — not NaN
Try It Yourself

How It Works

  1. No digits. "hello" has no leading integer for base 10 → NaN.
  2. Empty string. Same result — nothing to parse.
  3. Detect failure. Use Number.isNaN (not === NaN).
  4. Partial success. "15.9" still yields 15 — not a failure. Use parseFloat if you need the fraction.

Browser & Runtime Support

Number.parseInt() is part of ES2015 (as a Number static) and is Baseline Widely available. Global parseInt has existed much longer.

✓ Baseline · ES2015

Number.parseInt()

Supported in Chrome, Firefox, Safari, Edge, and Node.js. Safe for modern apps; global parseInt works even in very old environments.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Number.parseInt Excellent

Bottom line: Use Number.parseInt(s, radix) for new code. Always pass an explicit radix.

Frequently Asked Questions

Number.parseInt(string, radix) reads a string and returns an integer. Optional radix sets the base from 2 to 36. Example: Number.parseInt("42", 10) is 42; Number.parseInt("ff", 16) is 255.
Yes. Call it on Number itself: Number.parseInt(s, radix). It is the same function as the global parseInt — Number.parseInt === parseInt is true.
radix is an optional integer from 2 to 36 for the numeric base. Use 2 for binary, 10 for decimal, 16 for hexadecimal. Always pass 10 for everyday decimal parsing so the base is never ambiguous.
Parsing stops at the first character that is not valid for the chosen radix. Number.parseInt("42px", 10) returns 42. If nothing valid is found at the start, the result is NaN.
Number("42px") is NaN because the whole string must be a valid number. Number.parseInt("42px", 10) is 42 because it reads a leading integer prefix.
It is Baseline Widely available (ES2015) and supported in every modern browser and Node.js.

Next: parseFloat()

Learn how to parse floating-point numbers and keep the fractional part.

parseFloat() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful