🟡 Medium'this' Binding💻 Output Question

setTimeout this loss

💡

Hint

setTimeout callbacks lose their this. Fix with arrow function: setTimeout(() => { this.seconds++ })

What does this output?

const timer = {
  seconds: 0,
  start() {
    setTimeout(function() {
      this.seconds++;
      console.log(this.seconds);
    }, 100);
  }
};

timer.start();

Correct Output

NaN

Why this output?

Explanation: The regular function callback passed to setTimeout loses context. this becomes the global object (or undefined in strict). global.seconds is undefined, undefined++ is NaN.

Key Insight: setTimeout callbacks lose their this. Fix with arrow function: setTimeout(() => { this.seconds++ })

More 'this' Binding Output Questions

🟡 MediumMethod extracted from object→🟡 MediumArrow function this→🔴 Hardthis in nested function→🔴 Hardbind creates new function→

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz