Questions
18 of 19
1Explain the 5 rules that determine the value of this in JavaScript. Walk through each with an example.
2What is the default binding of this? How does strict mode change it?
3What is the difference between implicit and explicit binding? When does implicit binding get lost?
4How does this behave differently in arrow functions vs regular functions? Why?
5What does new binding do to this? What happens internally when you use new?
6Can this inside an arrow function be changed using .call(), .apply(), or .bind()? Why or why not?
7What is the value of this in a class constructor? What about in a class method called as a callback?
8What is the difference between call, apply, and bind? When would you use each?
9Explain how this works in event listeners. How do you preserve the correct this when using class methods as event handlers?
10How does this behave in a module (ESM) at the top level vs CommonJS?
11What is 'context loss' and what are the three most common ways to fix it in production code?
12How does Function.prototype.bind work under the hood? Can you implement a polyfill for it?
13How does this behave in prototype chain method calls? Does it refer to the instance or the prototype?
14When mixing ES6 classes with prototype manipulation, how can this become unpredictable?
15How do React class components use this, and why did binding in the constructor become a common pattern? How did arrow function class fields solve it?
16In what real-world scenarios have you encountered this-related bugs? How did you debug and fix them?
17What are the trade-offs between using arrow functions everywhere to avoid this confusion vs using regular functions with explicit binding?
18How would you explain the this keyword to a junior developer in one analogy?
19Can you think of a scenario where using .bind() causes a memory issue? How would you address it?
18 / 19

How would you explain the this keyword to a junior developer in one analogy?

Difficulty: 5/10
execution context, binding, arrow functions

Think of this as a sticky note that says 'my current owner.' The owner changes depending on how the function is called: the object before the dot, the object created by new, or whatever you explicitly set with call/apply/bind.

Imagine a name tag that says 'Owner: ______'. When you call a function as a method on an object (obj.sayHi()), the tag gets filled with that object's name. When you call a function alone (sayHi()), the tag might be blank (undefined) or default to the global name tag, depending on rules. With bind, you can permanently write a name on the tag. With call or apply, you can temporarily hand the tag to someone else. Arrow functions, however, don't get their own tag; they just look at the tag of the person standing next to them (their lexical scope).

Scenario Questions

0-2 years experience

  1. 1You have an object `const user = { name: 'Ada', greet() { console.log(this.name); } };`. How would you call `greet` so that it logs the name correctly?
  2. 2If you attach a plain function as an event listener on a button, what will `this` refer to inside that function when the click fires?
  3. 3What will `console.log(this)` output inside a function that you invoke with `myFunc.call(null)` in strict mode?

2-5 years experience

  1. 1You pass a class method `this.handleClick` as a callback to `addEventListener` without binding it. Why does it break and how would you fix it?
  2. 2In a React class component you bind a method in the constructor. Explain why the binding is needed and what would happen if you omitted it.
  3. 3You refactor a regular function that uses `this` into an arrow function and notice its behavior changes. What trade‑offs are you making?

5-8 years experience

  1. 1Design a chainable API (e.g., `builder.setA().setB().build()`) ensuring each method’s `this` always refers to the same builder instance, even when methods are extracted and called separately.
  2. 2Your large codebase has many functions that rely on implicit `this` and now break when used with `apply`. Propose a migration plan to make the codebase more robust.
  3. 3A Node.js module exports a function that accesses configuration via `this.config`. Discuss the pitfalls when the module is required in different contexts and how you would restructure it.

8+ years experience

  1. 1Your organization is migrating from prototype‑based objects to ES6 classes and modules. How would you orchestrate the transition of `this` usage across multiple services while keeping runtime errors low?
  2. 2You need to enforce correct `this` binding in a monorepo. Sketch a lint rule or TypeScript utility to catch improper usage and discuss its maintenance implications.
  3. 3In a micro‑frontend architecture each micro‑app may have its own global `this`. How would you isolate or standardize `this` handling to prevent cross‑app conflicts?

Follow-up Questions

  • Can you write a short snippet that demonstrates the difference between a regular function and an arrow function regarding this?
  • What edge cases should we watch for when using this in asynchronous code?
  • How would you test that a component correctly preserves its this binding?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.