Course contentsShow
← JavaScript
Lesson 560 of 2,72314. The 'this' KeywordFree lesson

call() vs apply(): When to Use Each

Comparing call and apply: choosing based on whether you have individual args or an array.

call() vs apply(): When to Use Each

You'll learn: How to decide between call() and apply() based on whether your arguments are individual values or already in an array.

The Core Difference

Both call() and apply() let you manually set this and invoke a function immediately. The only difference is how you pass arguments:

  • call() — arguments listed individually: func.call(thisValue, arg1, arg2, arg3)
  • apply() — arguments bundled in an array: func.apply(thisValue, [arg1, arg2, arg3])

Think of it like ordering food: call() is saying "I want a burger, fries, and a drink" (listing each item), while apply() is handing over a written list: "Here's my order" (array).

When to Use call()

Use call() when you know the arguments ahead of time and they're separate values:

function introduce(greeting, punctuation) {
  console.log(`${greeting}, I'm ${this.name}${punctuation}`);
}

const user = { name: 'Alice' };
introduce.call(user, 'Hello', '!'); // "Hello, I'm Alice!"

When to Use apply()

Use apply() when your arguments are already in an array or when you don't know how many there will be:

function sum(a, b, c) {
  return a + b + c;
}

const numbers = [5, 10, 15];
const result = sum.apply(null, numbers); // 30

This is especially useful with Math.max() or Math.min():

const scores = [88, 92, 76, 95];
const highest = Math.max.apply(null, scores); // 95

Key Takeaway: Use call() when you have individual arguments to pass; use apply() when your arguments are already in an array. The mnemonic: "Apply takes an Array."