What is the difference between call, apply, and bind in JavaScript

· Category: JavaScript

Short answer

call and apply invoke a function immediately with a specified this context, while bind returns a new function with this permanently set for later invocation.

Key differences

Method Invocation Arguments Use case
call Immediate Comma-separated Pass known discrete args
apply Immediate Array-like Pass dynamic array of args
bind Deferred Partial application Create callbacks with fixed context

Example

function introduce(greeting, punctuation) {
  console.log(`${greeting}, I'm ${this.name}${punctuation}`);
}
const person = { name: 'Sara' };
introduce.call(person, 'Hello', '!');
introduce.apply(person, ['Hi', '.']);
const sayHello = introduce.bind(person, 'Hey');
sayHello('?');

When to use each

  • Use call when you have a fixed list of arguments.
  • Use apply when arguments already live in an array.
  • Use bind when you need to pass a method as a callback without losing this.