xs = ['10','10','10'] [ '10', '10', '10' ]
xs.map(parseInt) [ 10, NaN, 2 ] xs.map(parseFloat) [ 10, 10, 10 ]
why is the result 10,nan,2 for first one? why the second one is right?
xs = ['10','10','10'] [ '10', '10', '10' ]
xs.map(parseInt) [ 10, NaN, 2 ] xs.map(parseFloat) [ 10, 10, 10 ]
why is the result 10,nan,2 for first one? why the second one is right?
.map() passes multiple arguments to its callback.
parseInt() uses the 2nd argument that .map() passes as the radix distorting its result.
parseFloat(), on the other hand, only expects one argument so it works as expected.