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

Can you think of a scenario where using .bind() causes a memory issue? How would you address it?

Using .bind() inside a loop or render method creates new function instances repeatedly, leading to increased memory usage and potential performance issues. Address by binding once (e.g., in constructor) or using arrow functions.

A common memory issue occurs when .bind() is called inside a loop or a component's render method (e.g., React). Each call creates a new function object, which can cause memory bloat and force unnecessary re-renders. Example: items.map(item => <button onClick={this.handleClick.bind(this, item)}>Click</button>) creates a new bound function per item on every render. Fix by binding the method once in the constructor, using arrow function class fields, or using data attributes and a single handler.

Difficulty: 6/10
Topics: function binding, memory leaks, event listeners

Scenario Questions

0-2 years experience
  1. 1

    You need to attach a click handler inside a for‑loop that logs the loop index. If you use .bind() to capture the index, what could happen to memory as the loop runs many times?

  2. 2

    In a simple class component you bind a method in the constructor. When you create many instances of that component, how does the binding affect memory usage?

2-5 years experience
  1. 1

    After navigating between pages, you notice the browser's memory keeps rising. Each page adds event listeners using .bind() but never removes them. How would you debug the issue and what fix would you apply?

  2. 2

    A Node.js request handler creates a bound callback and pushes it into a global array for later processing. Explain why this can leak memory and how you would redesign it.

5-8 years experience
  1. 1

    You're building a reusable UI library where consumers pass callbacks. The library stores those callbacks internally for later invocation. How would you design the API to avoid memory leaks caused by repeatedly calling .bind() on those callbacks?

  2. 2

    Your codebase has hundreds of DOM event registrations that use .bind() inside component constructors. At scale, this is causing noticeable memory bloat. What systematic refactoring strategy would you propose?

8+ years experience
  1. 1

    During a migration of a legacy monolith to a micro‑frontend architecture, you discover extensive use of .bind() for event registration, leading to memory bloat across teams. How would you plan the migration to eliminate these leaks while keeping the rollout low‑risk?

  2. 2

    You need to establish a company‑wide guideline to prevent memory issues from function binding. What policies, code‑review checks, and automated tooling would you put in place to enforce safe usage of .bind across many repositories?

Follow-up Questions

  • How would you verify that a leak is actually caused by bound functions?
  • What trade‑offs exist between using .bind and arrow functions in this context?
  • Can you think of any tooling or lint rules that help catch this pattern?