[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt [Back]  [Original]

Number.parseInt() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Number.parseInt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.

Number.parseInt() .

In this article

function roughScale(x, base) {
  const parsed = Number.parseInt(x, base);
  if (Number.isNaN(parsed)) {
    return 0;
  }
  return parsed * 100;
}

console.log(roughScale(" 0xF", 16));
// Expected output: 1500

console.log(roughScale("321", 2));
// Expected output: 0

js
Number.parseInt(string)
Number.parseInt(string, radix)

string

, . .

radix Optional

2 36 , string ( ) .

radix 0 10 . , 0x 0X 16 .

string .

radix 2 36 , NaN .

Number.parseInt vs. parseInt

parseInt() .

js
Number.parseInt === parseInt; // true

. parseInt() .

Specification
ECMAScript 2027 LanguageSpecification
# sec-number.parseint


Web Proxy Viewer  |  New URL  |  Original Page