0

So I am creating a simple object with one of the properties being a function... I cannot figure out why when I call it, it outputs undefined!

Here is the code...

const team = {
  partner1: "Matthew",
  partner2: "Boab",
  sayTeamNames: (teamObj) => {
    console.log(`${this.partner1} and ${this.partner2}`)
  }
}

team.sayTeamNames();

The output I get is...

'undefined and undefined'

I am fairly sure my syntax is correct. Any help would be much appreciated!

DaShaman
  • 147
  • 1
  • 11
  • 1
    Arrow functions (`=>`) do not work like old-school functions, and `this` is not bound to the calling object context. – Pointy Nov 25 '21 at 21:03
  • 1
    Also you don't need the parameter if you're not going to pass it. – Pointy Nov 25 '21 at 21:04

0 Answers0