Thursday, 5 September 2013

Does the var becomes a function because of a javascript function stored in a var?

Does the var becomes a function because of a javascript function stored in
a var?

In below example about Scope,I dont understand that how could a variable
is running as a function? in here var f is running as f(). However, is
this a sound method to run f in javaScript? Why? Is it because var f
stored a function?
var myFunction = function() {
var foo = "hello";
var myFn = function() {
console.log( foo );
};
foo = "ddd";
return myFn;
};
var f = myFunction();
f(); // "world"
});
Thanks!

No comments:

Post a Comment