Use the Rest Operator with Function Parameters-- Getting error i.e, The sum function uses the ... spread operator on the args parameter

Tell us what’s happening:

Your code so far


const sum = (function() {
  "use strict";
  return function sum(...w) {
    return w.reduce((a, b) => a + b, 0);
  };
})();
console.log(sum(1, 2, 3)); // 6

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Your function doesn’t have an argsparameter but a w parameter

1 Like