Search code examples
javascriptecmascript-6built-in

Why use Number.parseInt instead of parseInt()?


From documentation:

This method behaves identically to the global function parseInt()

But, as it's experimental, the compatibility is worst. For example, is not available in IE or Safari.

So, why should a developer use Number.parseInt()?


Solution

  • The use of Number.parseInt being encouraged over parseInt() is due to a trend in the JavaScript community of get away from using globals. The Mozilla documentation on Number.parseInt states:

    ...and is part of ECMAScript 2015 (its purpose is modularization of globals).

    There you have it. It's because of global-phobia :)