Why should I use additional function to return other function inside the first one like in the task
const sum = (function() {
"use strict";
return function sum(...args ) {
return args.reduce((a, b) => a + b, 0);
};
})();
console.log(sum(1, 2, 3)); // 6
Can I use this instead?
const sum = function sum(...args ) {
return args.reduce((a, b) => a + b, 0);
};
console.log(sum(1, 2, 3)); // 6
And in general please, tell me if there any difference and which is better? Thanks in advance.