of execution are the same, but what is the difference between the two pieces of code?
var scope = "global scope";
function checkscope(){
var scope = "local scope";
function f(){
return scope;
}
return f();
}
checkscope();
---------------------------------------
var scope = "global scope";
function checkscope(){
var scope = "local scope";
function f(){
return scope;
}
return f;
}
checkscope()();
The difference is that in one you have return f();, and the other you have return f;
I guess the 1st one returns the value, returned by the function f() - after executing it. And, the 2nd one just returns the function f().
Обсуждают сегодня