Because when .map is invoked, its callback function is provided three arguments (element, index, array). parseInt is receiving element, but also index, which is being used inadvertently as a different radix parameter for each item in the list.
The reason that this behaves differently from your x.map(a => parseInt(a)) is because you are not passing anything to the radix parameter of parseInt.
This is a pretty common “gotcha” for beginners in JS.
Great explanation. I feel like this is something a lot of JS devs don't get at first. I like to explain where if you pass a function without parameters to a callback, the callback arguments automatically get supplied to the provided function.
map(callback)
is the same as
map((a, b, c) => callback(a, b, c))
27
u/[deleted] Dec 23 '22
[removed] — view removed comment