I was studying this keyword in javascript when I came across this example
const TESgames = {
titles: ['Arena', 'Daggerfall', 'Morrowind', 'Oblivion', 'Skyrim'],
seriesTitle: 'The Elder Scrolls',
listGames: function() {
this.titles.forEach(function(title) {
console.log(this.seriesTitle + ': ' + title);
});
}
};
TESgames.listGames();
Here why is this.seriesTitle
undefined.
From my understanding, context of this
depends on the function which is calling it? Does forEach and other function (like .map) etc always depends on global scope? that's why it is undefined