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

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;

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.