What is the difference between call and apply?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
call and apply both invoke a function while explicitly setting its this value. The difference is only in how the function arguments are passed: call takes them one by one, while apply takes them as an array or array-like object.
What They Both Do
Suppose you have a function that depends on this:
Normally, calling introduce() directly would leave this undefined or bound differently depending on the context. call and apply let you control that.
call: Arguments Passed Individually
With call, arguments come after the this value:
This is equivalent to saying:
- run
introduce - use
personasthis - pass
"JavaScript"and5as normal positional arguments
call is convenient when you already have the arguments separately.
apply: Arguments Passed as an Array
With apply, the second argument is one array or array-like collection:
This is useful when the arguments are already stored in a list-like structure and you want to spread them into the function call.
That is the whole mechanical difference:
- '
call(thisArg, arg1, arg2, ...)' - '
apply(thisArg, [arg1, arg2, ...])'
A Classic Example with Math.max
apply used to be a common way to pass an array into functions such as Math.max:
In modern JavaScript, the spread operator is usually clearer:
That is why apply is less prominent in everyday code than it used to be.
They Are Also About Borrowing Methods
Another use case is method borrowing. For example, you can use an array method on an array-like object by controlling this.
Here slice is borrowed from Array.prototype, and call makes it run against the array-like arguments object.
This pattern appears less often today because many older array-like problems are easier to solve with newer JavaScript features, but it is still a useful concept for understanding call and apply.
bind Is Related but Different
People often compare call, apply, and bind together. bind does not invoke the function immediately. It returns a new function with this pre-bound.
So:
- '
callinvokes now' - '
applyinvokes now' - '
bindreturns a new function for later'
Understanding that distinction prevents a lot of confusion.
Common Pitfalls
- Thinking
callandapplydiffer inthisbehavior. They do not; they differ in argument passing. - Using
applywhen you already have separate arguments, which makes the code harder to read. - Forgetting that modern spread syntax often replaces old
applypatterns more cleanly. - Confusing
bindwith immediate invocation tools such ascallandapply. - Assuming
thisrebinding matters in arrow functions the same way it does in normal functions. Arrow functions do not have their ownthis.
Summary
- '
callandapplyboth invoke a function with an explicitthisvalue.' - '
calltakes arguments one by one.' - '
applytakes the arguments as an array or array-like object.' - Modern JavaScript often replaces some
applyuse cases with the spread operator. - '
bindis related, but it creates a new function instead of calling immediately.'

