21
loading...
This website collects cookies to deliver better user experience
function outer(a){
return function inner(b){
return a + b;
}
}
outer(5)(5); // 10
function counter(){
let count = 0;
return function(){
count++;
return count;
}
}
const counter1 = counter();
counter1(); // 1
counter1(); // 2
const counter2 = counter();
counter2(); // 1
counter2(); // 2
counter1(); // 3 this is unaffected by counter2.
console.log(count);
// Uncaught ReferenceError: count is not defined - because it is private!