+ 6
What's the difference between new Number() and parseInt() in JavaScript?
We can use Number() and parseInt() but the job the same?
2 ответов
+ 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.