Repaso
EspaƱol
Frontend & WebIntermediateFE-47

What does this print?

const nums = [1, 2, 3, 4];
const result = nums
  .filter(n => n % 2 === 0)
  .map(n => n * 10)
  .reduce((sum, n) => sum + n, 0);
console.log(result);

Options

  1. 60 (Correct option)
  2. 100
  3. 20
  4. [20, 40]

Answer

60

Why

The chain runs step by step:

  • filter(n => n % 2 === 0) keeps even numbers: [2, 4].
  • map(n => n * 10) multiplies each: [20, 40].
  • reduce((sum, n) => sum + n, 0) adds them starting from 0: 20 + 40 = 60.

These three array methods (filter, map, reduce) never change the original array; they return new values.

Remember

filter keeps, map transforms, reduce combines.

Key terms

Practice this question in Repaso