What is the difference between map(func)
and map(function(x) { return func(x); })
?
Consider this example:
const lines = '1\n2\n3';
const result = lines.split('\n').map(parseInt);
console.log(result )
This returns [1, NaN, NaN]
which is not what I expected.
However:
const lines = '1\n2\n3';
const result = lines.split('\n').map(function(x){ return parseInt(x)});
console.log(result)
returns the expected: [1, 2, 3]
. What is the difference between these two forms and why in the first example the result is not [1, 2, 3]
?