I'm a bit confused with objects in JavaScript...
I wrote an object:
const gix = {
firstName: "John",
lastName: "Johnson",
yearOfBirth: 2000,
profession: "IT",
friends: ["Mark", "Luke", "John"],
driversLicence: true,
age: function () {
this.calcAge = 2022 - this.yearOfBirth;
return this.calcAge;
},
};
gix.age();
console.log(gix);
Why is the console log of the whole object not showing the calculated value but is showing age: f()
ageis a function. The question is, why do you expect it to show you a value? Just imagine if the function accepted parameters, which parameters should it use in order to show you a result? Obviously JavaScript doesn't know it, so it just tells you that the property contains a functioncalcAge, doesn't it?