Accumulator

noun

say it: “uh-KYOO-myuh-lay-ter” /əˈkjuːmjəleɪtər/

The running result that reduce() carries from one item to the next, such as a total so far. It starts from the value you give reduce() and ends as the answer.

What is Accumulator in JavaScript?

Accumulator — The running total that reduce() carries from item to item. It starts at the value you give, each call of your function returns its new value, and that value is handed to the next call. When the items run out, it's the answer.

const scores = [120, 45, 300];
const total = scores.reduce((runningTotal, score) => runningTotal + score, 0);
console.log(total); // 465

In a sentence

  • “In reduce((total, seconds) => total + seconds, 0), total is the accumulator, and it started at 0.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects