Reputation: 139
Trying to understand why is "undefined" returned when consoling out the output.
var learnFn = (function(){
var callMe = function(){
console.log('hi');
}
return {
name:"tom",
callMe: callMe
}
})();
console.log(learnFn.callMe());
Output:
"hi"
undefined
Upvotes: 0
Views: 43
Reputation: 944016
The function you are calling:
var callMe = function(){ console.log('hi'); }
… has no return
statement. So it returns undefined
(which you then log, after the console.log
statement inside that function has run).
Upvotes: 3