I don't understand why my returned function didn't change the value of the variable from the outer function.
Hi, I wrote js function:
function num() {
let number = 0;
console.log(number)
return function() {
return number++
}
}
then run it once. let add = num()
After that I run add()
multiple times and it returned my number variable with new values, but when I decided to run num()
function, in the console it would still return 0, as value of number. and I don't understand why this happens, because isn't returned function changing the value of number?