Difference Between call, apply and bind
Learn the difference between call, apply and bind in JavaScript — how each sets this, passes arguments and defers execution, with examples and interview tips.
Expected Interview Answer
call, apply and bind all set the value of this inside a function: call and apply invoke the function immediately, while bind returns a new function with this permanently fixed for later use.
The only difference between call and apply is how arguments are passed — call takes them as a comma-separated list, while apply takes them as a single array. bind does not run the function at all; it produces a bound copy whose this (and optionally some leading arguments) are locked in, which you can call whenever you like. All three are used to borrow methods, control this in callbacks, and partially apply arguments.
- Explicitly control the value of this
- Borrow methods from other objects
- apply spreads array data as arguments
- bind fixes this for callbacks and event handlers
- bind enables partial application (preset arguments)
AI Mentor Explanation
Think of a coaching drill you can run for any player. call is telling one specific batter 'do this drill now' with instructions listed one by one. apply is the same 'now' command but you hand over a whole checklist of instructions at once. bind is pre-assigning the drill to a batter so it runs later exactly when you signal, always for that same player.
Step-by-Step Explanation
Step 1
Understand this
All three methods control what this refers to inside a function when it runs.
Step 2
Use call for immediate, listed args
fn.call(thisArg, a, b) invokes fn right away with this set and arguments passed individually.
Step 3
Use apply for immediate, array args
fn.apply(thisArg, [a, b]) is identical to call but takes arguments as a single array.
Step 4
Use bind to defer
const bound = fn.bind(thisArg, a) returns a new function with this and leading args fixed, to call later.
Step 5
Pick by need
Choose call/apply when running now, bind when you need a reusable pre-configured function such as a callback.
What Interviewer Expects
- Knowing all three set the value of this
- call vs apply differ only in argument form
- bind returns a new function instead of invoking
- A method-borrowing or callback use case
- Understanding partial application with bind
Common Mistakes
- Thinking bind invokes the function immediately
- Confusing which of call and apply takes an array
- Forgetting bind returns a brand-new function
- Not knowing arguments passed to bind are prepended
Best Answer (HR Friendly)
“call, apply and bind all let you decide what the word this points to inside a function. call and apply run the function immediately — call lists the inputs one by one and apply gives them as a list — while bind hands back a ready-made version of the function to run later.”
Code Example
function greet(greeting, punct) {
return greeting + ', ' + this.name + punct;
}
const user = { name: 'Grace' };
greet.call(user, 'Hello', '!'); // 'Hello, Grace!'
greet.apply(user, ['Hi', '.']); // 'Hi, Grace.'const user = { name: 'Grace' };
function greet(greeting) {
return greeting + ', ' + this.name;
}
const greetGrace = greet.bind(user, 'Welcome');
greetGrace(); // 'Welcome, Grace' — runs later with this fixedFollow-up Questions
- When would you prefer apply over call?
- How does bind enable partial application?
- What does bind do with arguments passed at bind time?
- Can you use apply to find the max of an array without spread?
- How do arrow functions interact with call, apply and bind?
MCQ Practice
1. Which method passes its function arguments as a single array?
apply takes the arguments as one array, while call takes them individually as a comma-separated list.
2. What does bind return?
bind does not invoke the function; it returns a new function with this (and any preset arguments) permanently fixed.
3. call and apply differ in that:
Both invoke immediately and set this; the only difference is call lists arguments individually while apply uses an array.
Flash Cards
What does call do? — Invokes a function immediately with a given this and arguments listed individually.
What does apply do? — Invokes a function immediately with a given this and arguments passed as a single array.
What does bind do? — Returns a new function with this (and optional leading arguments) permanently fixed, to call later.
call vs apply? — Same behavior; call takes comma-separated args, apply takes an array of args.