So, I've discovered the answer.
When you pass just a function to .map
, it passes ALL the arguments on to the function:
var customParseInt = function() {
console.log('arguments', arguments);
}
var arr = ['1','2','3'];
arr.map(customParseInt);
Now, the first time it's called in your .map
, the first argument is '1' and the second argument is the current index of the array, which is 0.
So for the first array element, you're calling parseInt('1', 0);
And for the second array element, you're calling parseInt('2', 1);
-- again, first argument is the element, second argument is the index of the array.
If you look up the documentation, the second argument for parseInt is the radix. A radix of 0 does not error (probably because it defaults to a sensible value), but a radix of 1 or 2 makes the parseInt function behave fundamentally differently.