this, call, apply, bind Interview Questions
How this is decided, and when to use call, apply, and bind.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
How does this work in JavaScript? What do call, apply, and bind do?
this depends on how the function is called, not where it was written. A method call uses the object. A plain function is undefined in strict mode. new gives a new instance. Arrow functions take this from the outer scope. call and apply run the function now with a this I choose. apply takes arguments as an array. bind returns a new function with this fixed, which is why old React class handlers used bind. If they mix arrows and regular functions in a snippet, I walk through each call site. That is the whole question.
this in an arrow inside a method?
Lexical this from the enclosing method. That is why arrows keep the instance in callbacks. A regular function callback is undefined this in strict mode. I would not put an arrow on a prototype if I need dynamic this.
bind versus an arrow wrapper?
bind fixes this and can prepend args. Passing obj.method as a callback loses this. I would not bind in a render loop. Arrows are often clearer in modern code.
What does new do to this?
Creates object, sets this, sets prototype, returns this unless the constructor returns an object. Arrows cannot be newed. class is still this-based sugar.
call versus apply today?
apply takes an array. Spread is the modern version. I recognize apply in old code. Math.max.apply is now Math.max(...arr) with spread limits.
Practice with AI mock interviews
Run JavaScript mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required