Junior — Senior
Behavior of this in regular and arrow functions inside setTimeout
livecode
Task condition
What output will appear in the console after executing the script below?
(() => {
const entity = {
companyName: "EPAM",
fetchName() {
return this.companyName;
},
delayedFetch1() {
setTimeout(function () {
console.log("1:", this.fetchName());
}, 1000);
},
delayedFetch2() {
setTimeout(() => {
console.log("2:", this.fetchName());
}, 1000);
}
};
entity.delayedFetch1();
entity.delayedFetch2();
})();