Can anyone clearly explain how arguments are being passed to "log" function and then to "add" functions in the following code.
const add = (x,y) => console.log(x+y);
const log = func => (...args) => {
console.log(...args);
func(...args);
}
const logadd = log(add);
logadd(1,2,3); // 3 //1,2,3
I know the above code can also be written as follows
const add = function(x,y) {
console.log(x,y);
}
const log = function(func){
return function(...args){
console.log(...args);
func(...args)
}
}
const logadd=log(add);
logadd(1,2,3); // 3 //1,2,3
If logadd is function variable and if I pass it arguments how are the arguments passed to, first log function and then to add function? Any nice articles that explain this or can anyone explain this?