What is the difference between call and apply?

Created by flatlineLinked to 30.4m issues across 130 teams

tl;dr

The difference between call and apply in Javascript is that call takes in arguments one by one, while apply takes in arguments as an array.

For example, if we have a function add that takes in two arguments, a and b, we can call it using call like this:

add.call(this, a, b);

Or we can call it using apply like this:

add.apply(this, [a, b]);

In both cases, the function add will be called with the arguments a and b. The difference is that call takes in the arguments one by one, while apply takes in the arguments as an array.

We use cookies to personalize content
run ads, and analyze traffic.