Call, apply and bind in JavaScript ✨

Harsha
2 min readFeb 22, 2021

A function created in JavaScript inherits all the methods from its prototype which is Function.prototype (you can check all the methods of the Function.prototype by typing the same in any JS console)

Call, apply and bind are some of them . Let’s see what these are

1. Bind

The Bind method is used to set the ‘this’ of the function to the mentioned object.

Bind method example

Also, bind method creates a new copy of the previous function and doesn’t execute right away.

Bind method also takes parameters which can be passed to the functions. The execution of a function using bind and passing parameters can be seen below

Bind method taking parameters

2. Call

Similar to Bind, Call method of a function is also used to set the value of ‘this’ to the function that is being executed.

The major difference between call and bind methods is that while bind method creates a new copy of the function and doesn’t get executed immediately, the call method do not create a new copy of the function and executes immediately

Call method of a function

As you can see above, there is no need to execute the weather variable again to see the function execution. This is done automatically if we use call method, unlike the bind

Similar to bind method, call method also takes in parameters. If there are multiple parameters, they should be separated using commas

Parameters are sent as comma separated values

3. Apply

Apply method of the function is almost identical to Call method. The only difference between call and apply method is in Call method we send the parameters as comma separated values whereas in Apply we send all the parameters in the form of an array

Parameters are sent in the form of an array

Apply method also do not create a new copy of the function and executes the function immediately, similar to the call method

Thanks for reading. Have a good day 😃 👋

--

--