Learning javascript. Why first code is giving error where as second is not? In first code why this is being considered as window{} where as in second it is doing what it meant to do?
1st
const tahoe = {
mountains: ["Freel", "Rose", "Tallac", "Rubicon", "Silver"],
print: function(delay = 1000) {
setTimeout(function() {
console.log(this.mountains.join(' '));
}, delay);
}
};
tahoe.print();
2nd
const tahoe = {
mountains: ["Freel", "Rose", "Tallac", "Rubicon", "Silver"],
print: function(delay = 1000) {
setTimeout(()=> {
console.log(this.mountains.join(' '));
}, delay);
}
};
tahoe.print();