Sobes.tech
Back to tasks
Junior — Senior
29

Поведение this в обычной и стрелочной функции внутри setTimeout

Get help with live coding in real time with Sobes Copilot
Task condition

Какой вывод появится в консоли после выполнения приведённого ниже скрипта?

(() => {
  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();
})();