โ† Back to list

๐Ÿ”ฅ TOP bind() INTERVIEW QUESTIONS (with answers) 2025

โœ… 1. What does bind() do in JavaScript?

Mahua Chanda ยท 2025-11-19 04:00 ยท 0 claps ยท 1.9 min read
#javascript #bind
Open on Medium โ†—
Wiki topics: ๐ŸŒ ยท Web Development

๐Ÿ”ฅ TOP bind() INTERVIEW QUESTIONS (with answers) 2025

โœ… 1. What does bind() do in JavaScript?

Answer (short & perfect):

*bind() returns a new function with a permanently set this value and optional preset arguments. It does not execute the function immediately.*

โœ… 2. What is the difference between call, apply, and bind?

call()  โ†’ executes immediately, arguments individually
apply() โ†’ executes immediately, arguments as array
bind()  โ†’ does NOT execute, returns new function

โœ… 3. What will be the output?

const person = { name: "Mahua" };
function sayHi() {
  console.log(this.name);
}
const hi = sayHi.bind(person);
hi();

Answer: "Mahua"

Because bind() permanently binds this to person.

โœ… 4. Why do we need bind() in event listeners?

class Button {
  constructor() {
    this.count = 0;
    document.querySelector("#btn")
      .addEventListener("click", this.increment);
  }
increment() {
    console.log(this.count);
  }
}

โŒ Output โ†’ undefined Because this refers to the DOM element, not class instance.

โœ” Fix:

.addEventListener("click", this.increment.bind(this));

โœ… 5. What will be the output? (Very popular)

const obj = { a: 10 };
function f() {
  return this.a;
}
const f2 = f.bind(obj);
console.log(f2());
console.log(f());

Answer:

10
undefined (or window.a)

bind only affects the returned function, not the original one.

โœ… 6. Can bind() be chained?

function f() { return this.x; }
const a = f.bind({ x: 1 });
const b = a.bind({ x: 2 });
console.log(b());

Answer: 1

Once a function is bound, further binding has no effect.

โœ… 7. What happens if you pass null or undefined to bind()?

function check() { console.log(this); }
check.bind(null)();

Answer: If strict mode โ†’ this = null If non-strict mode โ†’ this = global object

โœ… 8. How does bind() support partial application?

function multiply(a, b) {
  return a * b;
}
const double = multiply.bind(null, 2);
console.log(double(5));

Output:

10

โœ… 9. Write the polyfill for bind() (100% asked in senior interviews)

Function.prototype.myBind = function(context, ...presetArgs) {
  const fn = this;
return function(...laterArgs) {
    return fn.call(context, ...presetArgs, ...laterArgs);
  };
};

๐Ÿ”ฅ 10. Why does bind return a function instead of calling the original function?

Answer:

Because the purpose of bind() is to create a new function where:

  • this is locked
  • some arguments may be pre-filled
  • the function can be called later

This is essential for:

  • event handlers
  • callbacks
  • currying
  • functional programming

๐Ÿง  11. What is the output? (Trick question)

const module = {
  x: 42,
  getX: function() {
    return this.x;
  }
};
const unbound = module.getX;
const bound = unbound.bind(module);
console.log(unbound());  // ?
console.log(bound());    // ?

Answer:

undefined (or window.x)
42

๐ŸŸฆ 12. Can bind() override arrow function this?

const obj = { value: 10 };
const f = () => this.value;
const f2 = f.bind(obj);
console.log(f2());

Answer: undefined Because arrow functions donโ€™t have their own this, and bind() cannot override it.

๐ŸŸช 13. Can bind() work with constructor functions?

Yes โ€” but the new binding is ignored if function is called with new.

function Person(name) { this.name = name; }
const Bound = Person.bind({ name: "Wrong" });
console.log(new Bound("Right").name);

Answer: "Right" Because when using new, JavaScript ignores the this from bind.


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
07a867d90ee8
slug
top-bind-interview-questions-with-answers-2025-07a867d90ee8
url
https://medium.com/@mahuachanda/top-bind-interview-questions-with-answers-2025-07a867d90ee8
canonical_url
https://medium.com/@mahuachanda/top-bind-interview-questions-with-answers-2025-07a867d90ee8
author_url
https://medium.com/@mahuachanda
status
ok
fetched_at
2026-06-15 20:49:13