Trying to figure out why self invoking function is preserving the private value while other type is not.
Does increase the value
var a = function(){
var myval=10;
return function(){
return myval++;
}
}();
console.log(a());
console.log(a());
console.log(a());
Output : 10,11,12
while this code does not increase the value
var a = function(){
var myval=10;
return function(){
return myval++;
}
};
console.log(a()());
console.log(a()());
console.log(a()());
Output :10,10,10