As we all know, this following will not run the a() function so the alert box will not appear
// 1st
function a() {
alert('A!');
return function() {
alert('B!');
};
};
and we know that the following code will run the a() function and alert box 'A!' will appear
// 2nd
function a() {
alert('A!');
return function() {
alert('B!');
};
};
a(); // calling function
However, if we run following code, the a() function will be called and alert box 'A!' will also appear, just like the second code above
// 3rd
function a() {
alert('A!');
return function() {
alert('B!');
};
};
var x = a(); // assigning function to new variable
QUESTION: why does this happen (on 3rd snippet)? we didn't call the a() function yet (my current understanding). Didn't we just assigning x to a() function?.