For type conversion, when should one use the primitive wrapper Number()
and when should one use parseInt()
?
I'm aware that parseInt()
allows you to specify a radix, will truncate decimals so that they become integers, and will parse up until the first NaN
it encounters in the input. The MDN documentation on the Number()
wrapper was less helpful.
My questions:
- Is there a general preference for using one or the other?
- Are there performance differences?
- Are there edge case differences in the two implementations?
Things I've tried: