Skip to content

The this Keyword

this is a special keyword that refers to the object that is executing the current function. Its value is determined by how the function is called (not where it’s defined).

  • Understand the four binding rules for this
  • Distinguish between default, implicit, explicit, and new binding
  • Understand how arrow functions handle this (lexical scoping)
  • Master call, apply, and bind
  • Avoid common pitfalls with this
flowchart TD
A["How is the function called?"]
A --> B["new binding"]
A --> C["Explicit binding"]
A --> D["Implicit binding"]
A --> E["Default binding"]
B --> B1["this = new object"]
C --> C1["call/apply/bind → this = specified"]
D --> D1["obj.method() → this = obj"]
E --> E1["Standalone call → this = global (or undefined in strict)"]
style B1 fill:#4CAF50
style C1 fill:#2196F3
style D1 fill:#FF9800
style E1 fill:#f44336
TopicDescriptionEst. Time
Default BindingStandalone function calls, strict mode10 min
Implicit BindingMethod calls, object context10 min
Explicit Bindingcall, apply, bind15 min
new BindingConstructor calls with new10 min
Arrow FunctionsLexical this, no own this15 min
Common PitfallsLosing this, event handlers, callbacks15 min
  • Functions and execution context
  • Objects and methods
  • Arrow functions
Default Binding → Implicit Binding → Explicit Binding → new Binding → Arrow Functions → Common Pitfalls
  1. new binding 🥇 — new foo() → this = new object
  2. Explicit binding 🥈 — foo.call(obj), foo.apply(obj), foo.bind(obj)
  3. Implicit binding 🥉 — obj.foo() → this = obj
  4. Default binding 4️⃣ — foo() → this = global/undefined