1function outer() {
2 var counter = 0; // Backpack or Closure
3 function incrementCounter() {
4 return counter++;
5 }
6 return incrementCounter;
7}
8
9const count = outer();
10count(); // 0
11count(); // 1
12count(); // 2
1function makeFunc() {
2 var name = 'Mozilla';
3 function displayName() {
4 alert(name);
5 }
6 return displayName;
7}
8
9var myFunc = makeFunc();
10myFunc();
11