0

I am trying to use the function in object literal to get a full name but am failing at it. The code I used can be seen below. What could I be doing wrong?

fullName function(){ 
return this.firstName +" "+this.lastName;
} 
console.log(person.fullName());

1 Answers1

0

If you want to use fullName() as a method of a person object, you first need a person object.

const person = { 
  firstname: "john",
  lastname: "doe",
  fullName() {
    return `${this.firstname} ${this.lastname}`
  }
}

console.log(person.fullName());
Angel
  • 100
  • 8