-2

I'm currently learning the use of the rest operator in javascript, and I saw this example from the tutorial. I am confused about where the arguments a and b in the arrow function come from, they have never been declared or passed anywhere. How could the function work?

const sum =(function() {
    return function sum(...args) {
        return args.reduce((a, b) => a + b, 0);
    };
})();
console.log(sum(1, 2, 3));
  • They have been declared - right there, in the code you've posted. And it's a callback; they're passed _when it's called back_. – jonrsharpe May 12 '22 at 12:37

0 Answers0