Question discussion

What is the output of the following JavaScript code?console.log([1, 2, 3, 4].map(x => x * 2).filter(x => x > 4).reduce((a, b) => a + b, 0));

1376Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following JavaScript code?

console.log([1, 2, 3, 4].map(x => x * 2).filter(x => x > 4).reduce((a, b) => a + b, 0));
  • A20
  • B14
  • C24
  • D12
Correct answer: B

Explanation

map gives [2, 4, 6, 8], filter (> 4) keeps [6, 8], and reduce adds them: 14.

Discussion 0

Nobody has replied yet. Start the discussion!