Why does the console print undefined when I access age property directly. I have to print calcAge function first in order to get the value.
const Osama = {
firstName: 'osama',
lastName: 'Shaikh',
birthyear: 1999,
job: 'developer',
friends: ['michael', 'peter', 'steven'],
haslicense: true,
calcAge: function () {
this.age = 2021 - this.birthyear;
return this.age;
},
};
console.log(Osama.age);