+ 6

What's the difference between new Number() and parseInt() in JavaScript?

We can use Number() and parseInt() but the job the same?

7th Dec 2018, 6:43 AM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
2 Antworten
+ 4
Number() accepts only "digit strings". For example: "34", "-56", "3.14", "6.022e23", etc. are all valid for Number() While, parseInt() accepts those strings which may or may not have non-digit character(s) at the end of string. For example: "34", "34foo" and "34bar34" will all return the number 34. But "foo34" will return NaN.
14th Dec 2018, 12:20 PM
777
777 - avatar