๐ฅ TOP bind() INTERVIEW QUESTIONS (with answers) 2025
โ 1. What does bind() do in JavaScript?
๐ฅ 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 setthisvalue 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:
thisis 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