In chapter 5 of Eloquent Javascript (https://eloquentjavascript.net/05_higher_order.html) there is an example that I'm having a hard time wrapping my head around.
function greaterThan(n) {
return m => m > n;
}
let greaterThan10 = greaterThan(10);
console.log(greaterThan10(11));
// → true
I get the initial call of the function and assigning n
to 10. It's when it's called a second time I don't understand how 11
would get passed to the variable m
(wouldn't the parameter still be n
? I almost want to think it would overwrite 10
with 11
).
When I do alert(greaterThan10)
it shows m => m > n
which I was also confused as to why it wouldn't show n
as 10
.