CKTIS / JavaScript
parseInt — reading an integer from text
parseInt reads a leading integer representation in a specified radix and returns a Number. It ignores subsequent invalid characters, so it does not validate the entire input string.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
parseInt(string, radix)parseInt(string, radix) converts its first argument to text, skips leading whitespace, and reads an optional + or - sign followed by digits valid for the radix. It returns a Number, not a BigInt. Number.parseInt refers to the same ECMAScript function, not a separate browser API.
Supply radix explicitly, usually as 10. After conversion to a signed 32-bit integer, valid radices are 2–36; other values except 0 produce NaN. An omitted radix or a value converted to 0 means 10, unless 0x or 0X follows the sign: then the radix is 16. The prefixes 0b and 0o are not automatically recognized.
Parsing stops at the first invalid character. Consequently, parseInt("12.9", 10) produces 12, and parseInt("42px", 10) produces 42. If no valid digit is read, the result is NaN; test it with Number.isNaN. This is a prefix parser, not a whole-string validator or a tool for rounding numbers.
Large results can lose precision because they use Number. Do not use this function to read arbitrarily large integers exactly.
Examples
console.log(parseInt(" -42px", 10));
console.log(parseInt("101", 2));
console.log(parseInt("0xFF", 16));
console.log(parseInt("12.9", 10));
console.log(parseInt("0b11", 10));
console.log(Number.isNaN(parseInt("px42", 10)));Result
-42 5 255 12 0 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.