function setupCounter(val){
console.log(val);
return function counter(){
console.log('counter func ', val);
return val++;
}
}
debugger
let counter1 = setupCounter(0);
console.log(counter1()); //0
console.log(counter1()); //1
Why the first counter1()
does not increment value and returns 0. But the second call increments the value to 1, as expected: here is what I've been debuggin