I have two questions regarding the following code sample:
function greaterThan(n) {
return m => m > n;
}
let greaterThan10 = greaterThan(10);
console.log(greaterThan10(11));
//returns true
From what I understand the function greaterThan(n)
returns a function which takes the parameter m
but here it starts to get tricky for me:
- Why is this
m
not declared and still properly working within this code sample? greaterThan10
is declared as a variable in line 4 and it is inheriting the value ofgreaterThan(10)
. How can it behave like a function in line 5, where this "variable" takes another integer?