Questions
3 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?
03 / 19

What is the difference between implicit and explicit binding? When does implicit binding get lost?

Implicit binding uses the object context before the dot, while explicit binding uses call/apply/bind to set this. Implicit binding is lost when a method is passed as a callback or assigned to a variable.

Implicit binding relies on the object that the method is called on (obj.method()), setting this to that object. Explicit binding uses call, apply, or bind to manually specify this. Implicit binding is lost when a method is extracted from its object, e.g., const fn = obj.method; fn(); — now it's a standalone function, and default binding applies. Example: const obj = { name: 'Test', log() { console.log(this.name); } }; const fn = obj.log; fn(); // undefined (implicit binding lost).

Difficulty: 5/10
Topics: this binding, implicit vs explicit, call/apply/bind

Scenario Questions

0-2 years experience
  1. 1

    You have an object user with a method login that uses this. If you write const loginFn = user.login; and later call loginFn(), what will this be inside loginFn and why?

  2. 2

    Write a short snippet that uses call to invoke a function show with a specific object as its this value.

  3. 3

    If you pass an object's method directly to Array.map, what happens to the implicit binding and how would you fix it?

2-5 years experience
  1. 1

    Your team added a utility function that relies on this and called it with items.forEach(utilFn). The function now throws because this is undefined. Walk me through how you'd debug and resolve the issue.

  2. 2

    We refactored a component to extract an event handler into a separate module, and clicking a button no longer updates state. Explain how implicit binding could be lost and what explicit binding options you have.

  3. 3

    A function that uses this is passed to setTimeout and doesn't behave as expected. Why does this happen and how would you modify the code?

5-8 years experience
  1. 1

    Our front‑end library mixes regular functions and arrow functions for component methods. Discuss the trade‑offs of using explicit bind versus arrow functions to preserve this in a reusable UI component.

  2. 2

    Design a generic event dispatcher that lets listeners register with a specific context. Explain how you'd handle implicit binding loss when invoking those listeners.

  3. 3

    When migrating legacy code that heavily relies on implicit this binding to a TypeScript codebase, what strategies would you use to avoid bugs caused by lost binding?

8+ years experience
  1. 1

    Our organization is moving to a framework that favors functional components and hooks, eliminating class‑based components. How would you plan the migration of existing class components that depend on implicit this binding while ensuring minimal runtime regressions?

  2. 2

    Propose a linting rule or build‑time check that catches patterns where implicit binding is likely to be lost (e.g., passing methods as callbacks). Explain how it would integrate into CI and its impact on cross‑team code quality.

Follow-up Questions

  • What would change if you used an arrow function for that method?
  • How does strict mode affect the default this value when binding is lost?
  • Can you think of a scenario where explicit binding might introduce a memory leak?