0
let person={
    firstName: 'Joe',
    lastname :'dawn',
    birthYear: 1995,
    job:"IT",
    family:['nikita','papa','mom'],
    age:(function(){
        console.log(this);

        return new Date().getFullYear()- this.birthYear;
    })()
};

When I am printing the age it is giving me NaN as the this.birthYear is giving undefined as a result.

The question is how can I call the function within the object and use the property of that object only in the function.

Teemu
  • 22,918
  • 7
  • 53
  • 106
yash vadhvani
  • 329
  • 2
  • 12

0 Answers0