Home
← All questions

The 'this' keyword and scope-based questions in JavaScript

MediumPremiumJavaScript

JavaScript interview practice: Explain how 'this' is determined and answer scope/context output questions.

Answer

this is determined by how a function is called, not where it's defined:

  1. Default: standalone call → undefined (strict) or global object.
  2. Implicit: obj.method() → this is obj.
  3. Explicit: call / apply / bind set this.
  4. new: this is the newly created object.
  5. Arrow functions: no own this; they capture this lexically from the enclosing scope.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium