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

How does Function.prototype.bind work under the hood? Can you implement a polyfill for it?

Difficulty: 6/10
this binding, function prototype, polyfill implementation

Function.prototype.bind returns a new function that, when called, has its this set to the provided value, with any arguments partially applied. A polyfill must handle new calls and chaining.

Simple bind polyfill

Under the hood, bind creates a closure that stores the original function (fn), the thisArg, and any pre-applied arguments (boundArgs). When the bound function is called, it uses apply to invoke the original function with the combined arguments. The polyfill must also handle the case where the bound function is used as a constructor with new, in which case the original this (the new object) should be preserved rather than the bound thisArg.

Scenario Questions

0-2 years experience

  1. 1You need to pass a callback to Array.map that uses this from the surrounding object. How would you use bind to make it work, and what would happen if you omitted it?
  2. 2Write a short snippet that creates a bound version of an object method and calls it later. What does this refer to inside the bound function?

2-5 years experience

  1. 1Our legacy module creates many bound functions and we’re seeing a memory leak. How would you investigate the cause and what alternatives could you consider?
  2. 2A teammate replaced a bound function with an arrow function, and a bug appeared when the function is instantiated with new. Explain why the bug occurs.
  3. 3Implement a polyfill for Function.prototype.bind that correctly supports being called with the new operator. Walk me through your approach.

5-8 years experience

  1. 1Our UI library ships a custom bind polyfill for older browsers, but bundle size and startup time have grown. How would you evaluate whether to keep the polyfill or drop support, and what trade‑offs are involved?
  2. 2Design a utility that provides bind‑like behavior but also memoizes bound functions to avoid creating duplicates. What edge cases must you handle to keep semantics correct?
  3. 3Explain how bind interacts with prototype inheritance when the bound function is used as a constructor. How would you test that your implementation preserves the prototype chain?

8+ years experience

  1. 1We are migrating a massive codebase from ES5 to ES6+ and want to remove all uses of Function.prototype.bind. What strategy would you propose to refactor safely, and how would you mitigate regression risk?
  2. 2Consider a cross‑team library that exposes a public API using bound methods. If you need to deprecate bind in favor of arrow functions, what architectural considerations and communication plan would you put in place?

Follow-up Questions

  • How would you ensure the bound function works correctly when used as a constructor?
  • What performance implications does using bind have in a tight loop?
  • How does your polyfill handle built‑in properties such as .length or .name?
Share

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