I have written a simple school object. I want to calculate the age and store it at the same time. However if I use an IIFE to do this, it seems like this becomes undefined. It works fine if I make it a normal function.
Please help!
const date = new Date();
const currentYear = date.getFullYear();
let school = {
name: "International Public School",
yoe: 1970,
age: (function() {
return currentYear - this.yoe;
})()
};
console.log(school);
Also can someone tell me how to achieve the same using arrow functions?