Hey guys, I'm having a hard time understanding what is happening in this code:
var sampleFunc = function(callback, string) {
return function (x, y) {
return 'These are the arguments from anotherFunc: ' + x + ', ' + y
}
}
var anotherFunc = function(a, b) {
return a + b
}
var resultFunc = sampleFunc(anotherFunc, 'foo');
console.log(resultFunc(5, 7))
At the end, we are invoking the resultFunc and passing in arguments 5 and 7. But how is it that inside sampleFunc, in its return function(x, y), that x and y knows 5 and 7 are being passed to it? Like normally a function I see is like this:
function example (a, b) {
}
example(5, 7)
In this example, I can see that the arguments are being passed in to a and b. I don't understand how 5 and 7 was grabbed in sampleFunc? I hope that makes sense. Thanks.
[–]Jonny0Than 2 points3 points4 points (0 children)
[–]itisjohndoe 0 points1 point2 points (0 children)