ES6 - Rest Parameter

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

What’s wrong with this code?! Why the console tells it’s not an arrow function???

const sum = (...num) => {
  let total = 0;
  const args = [...num];
  for (let i = 0; i < args.length; i++) {
    total += args[i];
  }
  return total;
}

sum(1, 2, 3);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36

Challenge Information:

ES6 - Use the Rest Parameter with Function Parameters

What’s this?

There is no args anymore

It is telling you about the expected function signature, it is not saying it isn’t an arrow function.

sum should be an arrow function which uses the rest parameter syntax (... ) on the args parameter.

When you see args in code blocks and referred to as a parameter it means it must be called args and it must be a parameter.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.