I'm struggling with this concept. By looking at below, I don't understand when I type on the console that "counter" is equal to the following below. How does it know just to pick up this piece of the code? How does this work?
function(val) {
count += val;
return console.log(count);
};
The Code
var incrementer = function(initialValue) {
var count = initialValue;
return function(val) {
count += val;
return console.log(count);
};
};
var counter = incrementer(5);
counter(3);
counter(1);