CodeZettaInterview Hub

JavaScript · this · Junior · Comparison

What are the differences between `call`, `apply`, and `bind`?

Short Interview Answer

`call` and `apply` invoke immediately with a chosen `this` (args list vs array); `bind` returns a new function with bound `this`/args.

Detailed Explanation

`fn.call(thisArg, a, b)` invokes `fn` with `this` set to `thisArg` and individual arguments. `fn.apply(thisArg, [a, b])` is the same but takes an array-like args list — useful for variadic forwarding before rest/spread. `fn.bind(thisArg, a)` returns a bound function that, when later called, uses that `this` (and partial args). Bound functions cannot be re-bound for `this` (though you can still wrap them). With `new`, a bound function's bound `this` is ignored in favor of the new instance (exotic bound function behavior).

Example

function greet(g) {
  return `${g}, ${this.name}`;
}
const user = { name: 'Ada' };
greet.call(user, 'Hi');
const hi = greet.bind(user, 'Hi');
hi();

Interview Tip

Mention that modern code often prefers spread over `apply`.

Common Mistake

Thinking `bind` invokes the function immediately.

Did you know this answer?