I have the following code:
var object = {
name: 'hello!',
func: function(){
console.log(this);
}
}
console.log(object.func());
What I expect is to see the object whenever I log object.func
and this does happen, I get to see the object. But right after the expected behavior I get unexpected behavior, undefined
is shown.
Here's what the result looks like:
{ name: 'hello!', func: [Function: func] }
undefined
What's the reason this is happening?
Side note:
I know I'm console logging something I shouldn't. However, this still doesn't explain to me why the undefined
.