0
const user = {
    name: "Mike",
    showName: function(){
        console.log(`I'm ${this.name}`);
    }
}


let fn = user.showName();
console.log(fn());

I don't actually get why showName with () is saying not a function, but showName without() return "I'm" +undefined..

Samuel Yoo
  • 21
  • 2
  • missing some context... r you in react? try this.user.name or just user.name <-- user.name got me the I'm Mike in console log – Jamie Garcia Oct 26 '22 at 14:36
  • You're calling the function, which returns `undefined`, so `fn` is `undefined`, and you can't call that as a function. Without the parentheses, you're assigning the function `user.showName` to `fn`, but then the `this` is wrong. For that, you should see [How does 'this' work?](https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work-and-when-should-it-be-used) – kelsny Oct 26 '22 at 14:37

0 Answers0