What's the Difference Between Number.parseInt() and window.parseInt() in JavaScript?

Number.parseInt() vs. parseInt()

There's absolutely no difference between Number.parseInt() and the global window.parseInt() method, as you can see below:

console.log(Number.parseInt === window.parseInt); // true

You may wonder then why there's even a need for Number.parseInt(). The answer is simply because JavaScript is moving towards the modularization of globals. Therefore, to future-proof your code, you should use Number.parseInt() instead of the global window.parseInt() method. If you're concerned about browser compatibility, then you could use the following polyfill:

if (Number.parseInt === undefined) {
    Number.parseInt = window.parseInt;
}

Hope you found this post useful. It was published . Please show your love and support by sharing this post.