10

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()?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Mario Levrero
  • 3,345
  • 4
  • 26
  • 57
  • because the developer uses a JS Engine that supports it? – epascarello Feb 05 '15 at 17:25
  • 4
    I don't think there's a better reason to use it. The function is exactly the same. They're just trying to remove global functions in ECMAScript 6, and making them class methods. – Romain Braun Feb 05 '15 at 17:26
  • possible duplicate of [What is the difference between parseInt(string) and Number(string) in JavaScript?](http://stackoverflow.com/questions/4564158/what-is-the-difference-between-parseintstring-and-numberstring-in-javascript) – Mike Cheel Feb 05 '15 at 17:26
  • 9
    From the docs you've linked: "`its purpose is modularization of globals`". – Teemu Feb 05 '15 at 17:27
  • 2
    The problem it's not supported in IE – DanKodi Aug 03 '17 at 05:44
  • @RomainBraun Do you have a source for the ECMAScript 6 global function removing? Because that would be a very good reason to switch to Number.* functions (reason is "global ones are deprecated and will be removed") Btw, `Number.parseFloat = parseFloat` should be a simple polyfill for IE (until you stop supporting this obsolete version of Edge) – Xenos Oct 17 '18 at 10:07

1 Answers1

10

The use of Number.parseInt being encourage overparseInt() 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 :)

Evan Wieland
  • 1,445
  • 1
  • 20
  • 36
  • What trend? I have never stumble up on someone ever using `Number.NaN` over just writing `NaN`. Maybe it's just me living under a rock – Endless Jun 18 '21 at 09:04