Skip to content
doubtly

2 answers

Answer: this refers to the object that is executing the current function; its value depends on how the function is called.

Common cases:

  • Inside an object method: this is the object before the dot.
    const student = {
      name: "Riya",
      greet() { return "Hi " + this.name; }
    };
    student.greet();   // "Hi Riya"
  • Plain function call: this is the global object (window in browsers), or undefined in strict mode.
  • Constructor (with new): this is the newly created object.
  • Event handler: this is the element that received the event.
  • Arrow function: it has no own this; it uses this from the surrounding code.
  • call, apply, bind: let you set this explicitly.

So this is decided at call time, not where the function is written (except for arrow functions).

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.