Trying to better understand the reduce method

I’m mostly just looking for a clarification here.

In the following example…

const sumOfAges = users.reduce((sum, user) => sum + user.age, 0);
console.log(sumOfAges); // 64

sum and user are arguments in the call back function. In this case, sum is known as the “accumulator” and user is “current element being processed”. There are two other optional arguments:

  1. index of that element
  2. the array upon which reduce is called

Finally, there is another (optional) parameter for the reduce method: an initial value. In the case of the example, it is 0.

Am I correct in summarizing that? Also, why do we refer to these things as arguments in the case of the callback function and parameters in the case of the reduce method?

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Use the reduce Method to Analyze Data

Link to the challenge:

The summary looks ok to me.

Technically you could call them all arguments. Reduce is a high order function that takes a function as an argument. That function itself must have a certain pattern to it’s arguments.

Your summary is correct. I use arguments and parameters interchangeably. There may be some obscure academic difference. In practice, they both are pretty much the same thing.