-2

Why aren't the two following statements equivalent:

const output1 = [..."123"].map(parseInt);
const output2 = [..."123"].map(e => parseInt(e));

console.log(output1);
console.log(output2);

What concept am I missing?

Alexander Nied
  • 12,804
  • 4
  • 25
  • 45
Ronnis
  • 12,593
  • 2
  • 32
  • 52
  • It would have been helpful to include the outputs - once you have NaN, parseInt and map together the answer's easy to find. Another common reason `.map(thing)` doesn't work, although it doesn't apply to this specific case, is https://stackoverflow.com/q/20279484/3001761. – jonrsharpe Dec 07 '21 at 14:15

1 Answers1

3

map will pass the index it is currently looking at as the second argument to the callback function.

parseInt takes an optional second argument which sets the radix (number base) it is parsing from.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335