I have the following JS Code:-
var Person = function(name, yob, job) {
this.name = name;
this.yearOfBirth = yob;
this.job = job;
this.calculateAge = function() {
this.age = 2020 - this.yearOfBirth;
};
};
var john = new Person("John Wick", 1990, "Assasin");
console.log(john);
john.calculateAge();
Running the file gives me the following Output:-
My Question is if I called the calculateAge() function after logging the Object. How did the logged Output Object get the "age" property. As JS is a scripting Language, The statements are executed in order so technically the logged John Wick object should not have the age property but it is not following the expected behaviour. Where am I going wrong??