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()?
This example shows the difference that parseInt() only returns an integer value whereas Number() returns all the digits including floating points.
The parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN . If not NaN , the return value will be the integer that is the first argument taken as a number in the specified radix .
The parseInt() function is used to accept the string ,radix parameter and convert it into an integer. The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With