🟑 Medium'this' BindingπŸ’» Output Question

Arrow function this

πŸ’‘

Hint

Arrow functions have no own this β€” they capture it from the surrounding scope at definition time.

What does this output?

const obj = {
  name: 'Bob',
  greet: () => {
    console.log(this?.name);
  },
  greetRegular() {
    console.log(this.name);
  }
};

obj.greet();
obj.greetRegular();

Correct Output

undefined
Bob

Why this output?

Explanation: Arrow functions inherit this from their lexical scope (where they were defined). At the object literal level, this is the global object/undefined β€” not the object. greetRegular() uses this = obj correctly.

Key Insight: Arrow functions have no own this β€” they capture it from the surrounding scope at definition time.

More 'this' Binding Output Questions

🟑 MediumMethod extracted from objectβ†’πŸ”΄ Hardthis in nested functionβ†’πŸ”΄ Hardbind creates new functionβ†’πŸŸ‘ MediumsetTimeout this lossβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz