var a = function() {
function someSetup(){
var setup = 'done';
}
function actualWork() {
alert('Worky-worky');
}
someSetup();
return actualWork;
}();
why the above code doesn't alert Worky-worky?it shows undefined.thank you
var a = function() {
function someSetup(){
var setup = 'done';
}
function actualWork() {
alert('Worky-worky');
}
someSetup();
return actualWork;
}();
why the above code doesn't alert Worky-worky?it shows undefined.thank you
Because you only return the function, not call it.
Perform a();
after this code execution, this will call the function that's returned by anonymous self-executing function, thus actualWork
.
you are trying to return a function that has no return type (actualWork()).
It doesn't do the alert() because you didn't call the function properly.
actualWork()
return actualWork;
is actually returning a variable, but because you didn't assign anything to that variable you're getting undefined back.
should do the trick.