JS: Number.parseInt (String to Number)

By Xah Lee. Date: . Last updated: .

parseInt

Number.parseInt(string)

Convert string to a integer.

// string to number
console.log(parseInt("324") === 324)
Number.parseInt(string, radix)

Use base radix.

// convert hexadecimal string to decimal
console.log(parseInt("ff", 16) === 255);
// true
// binary string to decimal
console.log(parseInt("1111", 2) === 15);
// true

Global Object

Number.parseInt is the same as the "parseInt" of the Global Object.

console.log(Number.parseInt === globalThis.parseInt)

JavaScript. Convert Decimal, Hexadecimal, Binary