Guides/JavaScript this Binding Rules

JavaScript this Binding Rules

this is decided by how a function is called — except for arrows, which close over this lexically.

Rajan Pandey · About the author

Rajan Pandey is a Full Stack AI Engineer with nearly 3 years of professional experience building production-ready web applications, SaaS platforms, and developer-focused tools. He specializes in JavaScript, TypeScript, React.js, Next.js, Node.js, and the MERN stack.He has worked on 15+ production applications across SaaS, EdTech, and GenAI products, with experience spanning frontend architecture, backend development, REST APIs, database design, authentication, and third-party integrations. StackTools was created as a way to make everyday development tasks simpler and JavaScript concepts easier to understand through interactive, browser- based tools.His goal is to build practical utilities that developers can use without unnecessary complexity, registration, or uploading their data to external servers.

Four call-site rules

  1. new — this is the new object.
  2. Explicit — call/apply/bind.
  3. Implicit — object before the dot: obj.method().
  4. Default — bare call: undefined in strict mode, global object in sloppy mode.
const obj = {
  n: 1,
  f() { console.log(this.n); },
};
obj.f(); // 1
const g = obj.f;
g(); // undefined (strict) — lost receiver
Open in Visualizer

Arrow functions

Arrows do not have their own this. They capture this from the enclosing lexical scope. call/apply cannot rebind it.

const obj = {
  n: 1,
  f: () => console.log(this && this.n),
};
obj.f(); // not 1 — lexical this from outer scope
Open in Visualizer

Method extraction pitfalls

Passing obj.method as a callback strips the receiver. Fix with obj.method.bind(obj), an arrow wrapper, or a class field arrow if you accept the tradeoffs.

When not to use this

For plain data transforms, pass arguments explicitly. this shines in object methods and class instance APIs; elsewhere it adds call-site fragility for little gain.

Try it live

Open the matching StackTools utility — runs in your browser.

Open JS Execution Visualizer