It is from a book called Eloquent JavaScript:
function noisy(f) {
return function(arg) {
console.log("calling with", arg);
var val = f(arg);
console.log("called with", arg, "- got", val);
return val;
};
}
noisy(Boolean)(0);
// → calling with 0
// → called with 0 - got false
The chapter is about higher order functions, and this block of code is to show how you can have functions that change other functions. I went through it, trying to understand what happens, but no luck. I would like to understand each line, especially where he declares the variable val.
Thank you.
EDIT: I see it as, function noisy that takes in argument f and returns another function(arg). Why is he declaring val = f(arg); How does that equal false? And why is he calling noisy with two arguments?