finding age in JavaScript
Anonymous
function Person(name,dob){
this.name=name;
this.birthday=new Date(dob);
this.calculateAge = function(){
const diff = Date.now()-this.birthday.getTime();
const ageDate = new Date(diff);
return Math.abs(ageDate.getUTCFullYear()-1970);
}
const brad11 = new Person('Brad','1993-08-29');
The above code is working fine the confusion here is in the line of return statement I am unable to understand the logic that why we are multiplying ageDate with getUTCFullyear and then subtracting 1970 from it .