I ran the code below, and the first alert was alert 'a.' After I clicked o.k., alert 'b' popped up immediately, but I don`t understand how this all worked.
Since a() is assigned to var newFunc
, when I hit enter after newFunc();
, it runs function a(), and function a() returns an anonymous function, but how does this anonymous function get called so that alert('B') pop up appears after I clicked o.k. on the alert A pop up?
function a(){
alert ('A');
return function() {
alert('B');
};
}
var newFunc = a();
newFunc();