8
I was seeing a comment from jbueno in chat and decided to test in the browsers IE, Firefox and Chrome, while running on the consoles this command:
['10', '10', '10'].map(parseInt);
He returned this to me:
[10, Nan, 2 Nan]
When the expected would be this:
[10, 10, 10]
But if I do so:
['10', '10', '10'].map(function(a) { return parseInt(a); });
He returns it perfectly:
[10, 10, 10]
I don’t understand why this happens, but I believe that maybe the parseInt
work the array of map
as a reference, that is to say, beyond the return
it modifies the reference directly to each loop beyond the return
, but I’m not sure.
What can it be?
It is irrelevant in this case, but remember that the callback also takes the source array as the third argument.
– patetico
@pathetically correct. I was editing and added this as well. Thank you.
– Sergio