|
Sure, but you're putting a workaround in – there really shouldn't be any need for that no-op arrow function. But you do actually need it in order to drop all but the first arguments. This is simple, straightforward, and wrong: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"].map(parseInt)
This doesn't work because map() stuffs a counter into the second argument of parseInt(), which is expecting a radix for its second argument. So the iterations of the map go like this: parseInt("1", 0)
parseInt("2", 1)
parseInt("3", 2)
…and so on, which obviously gives garbage results. JavaScript is littered with these kinds of weird edge cases. Even your example with the workaround isn't 100% reliable, it's browser-dependent – when you have leading zeros in your strings, some browsers will interpret them as octal, and some won't. |