i am trying to understand closure.How would you explain behavior of these two scenarios.
Scenario 1
<input type="button" value="Click me" onclick="alert(handle())"/>
<script>
var handle = (function(){
var count = 0;
return function(){
return ++count ;
}
})();
</script>
Scenario 2
<input type="button" value="Click me" onclick="alert(handle()())"/>
<script>
var handle = function(){
var count = 0;
return function(){
return ++count ;
}
};
</script>
aren't both scenarios same? why in first scenario outer function is called only one time and after first click, on every click inner function is called.