Question discussion

What is the output of the following JavaScript code?console.log(['1', '2', '3'].map(parseInt).join(' '));

2363Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following JavaScript code?

console.log(['1', '2', '3'].map(parseInt).join(' '));
  • ANaN NaN NaN
  • B1 2 3
  • C1 NaN 3
  • D1 NaN NaN
Correct answer: D

Explanation

map passes (value, index), so the calls are parseInt('1', 0) = 1, parseInt('2', 1) = NaN (radix 1 is invalid) and parseInt('3', 2) = NaN ('3' is not a binary digit).

Discussion 0

Nobody has replied yet. Start the discussion!