Javascript Interview-JavaScript Function Call

Photo by Chris Montgomery on Unsplash

I have started a series in which I will cover all relevant Javascript Interview topics. I already posted one article The javascript this keyword.

Today we will cover Javascript Function call, which is one of import Interview topic.

  1. Why do we use a call() Function?

So, with call(), an object can use another object method.

Let’s understand through an example.

So, you can see, this example calls the method fullName method of myName , on rameshName. Originally, rameshName has no any method fullName. But using call() function, we can access the method of another object.

Note: Even call() accepts arguments. In the above example, “demo” and “other” are the arguments.