can anyone figure out what this possibly means?
Below code is to sum all the arguments, and I called the function like 'addTogether(2)(3)' then it works....?
For my understanding, calling a function should look like this 'addTogether(2, 3)'. put all the arguments in a pair of parentheses not two pairs of parentheses??
Could anyone explain why it worked and how it works?
I did console.log to figure this out, If I console.log(arguments) the result would be { '0': 2 }
function addTogether() {
console.log(arguments) // result { '0': 2 }
var args = Array.from(arguments);
console.log(args) //result [2]
return args.some(n => typeof n !== "number")
? undefined
: args.length > 1
? args.reduce((acc, n) => (acc += n), 0)
: n => (typeof n === "number" ? n + args[0] : undefined);
}
// test here
console.log(addTogether(2)(3)); // result 5
question from:https://stackoverflow.com/questions/65915954/javascript-function-can-you-give-arguments-like-this