Why is the result of the execution of the following functions 2? Hasn"t counter been reinitialized each time it is called? Also, () () executes the function immediately, so why use var add =. Counter? is not called in return when add () is defined Confused for a long time, please help me to answer
var add=(function(){
var counter=0;
return function(){
counter+=1;
}
})();
add();
add();//2