I am trying to understand closures.
var a = 1; var g = function () { var a = a; return function() { console.log(a); } } g()(); As far as I know, the function invocation g()() should log the value of a, i.e. 1. But it is logging undefined on the console. I know my concept is weak somewhere, but am not able to figure out even after spending few hours. Can someone help?