I am reading about closures right now and am confused by this javascript code.
function makeAdder(x) {
return function(y) {
return x + y;
};
};
var add5 = makeAdder(5);
var add10 = makeAdder(10);
console.log(add5(2)); // 7
console.log(add10(2)); // 12
How does the console.log work? Since add5 = makeAdder(5), then isn't add5(2)) = makeAdder(5)(2)?
I am wondering how y = 2 is determined by javascript in this function, as the function only defines one argument x.
EDIT: Sorry to make it clear, what I was confused about was the fact that it appears like 5 and 2 are both being passed into makeAdder(x).