0

Here's a block of code that takes an array of strings and converts them into an integer.

To be more clear, it parses the numerical characters to integers.

console.log(['1', '2', '0'].map((num) => Number.parseInt(num)))

The above works as expected. However, the following shorthand does not work.

console.log(['1', '2', '0'].map(Number.parseInt))

You can run the code snippet and you will find that the first snippet logs the result 1, 2 and 0 as expected. However, the latter logs 1, NaN and 0.

Is there somewhere I am going wrong here in using this shorthand?

Black Wind
  • 313
  • 1
  • 8

0 Answers0