Medium'this' Binding💻 Output Question

this in nested object — direct parent wins

💡

Hint

this is always the object immediately before the final dot — not a parent object.

What does this output?

const outer = {
  name: 'outer',
  inner: {
    name: 'inner',
    greet() { return this.name; },
  },
};
console.log(outer.inner.greet());
const fn = outer.inner.greet;
console.log(fn?.call(outer));

Correct Output

inner
outer

Why this output?

Explanation: outer.inner.greet() — this is inner (the direct calling object). fn.call(outer) explicitly sets this to outer.

Key Insight: this is always the object immediately before the final dot — not a parent object.

More 'this' Binding Output Questions

EasyMethod call — this is the calling objectEasyArrow function has no own this — inherits lexicallyMediumbind permanently fixes this — call cannot override itMediumcall vs apply — same result, different syntax

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz