What is the difference between .call() and .apply()?

Forums JavaScriptWhat is the difference between .call() and .apply()?
Staff asked 2 years ago

Answers (1)

Add Answer
Jaydip Mali Marked As Accepted
Staff answered 2 years ago

Let us understand the differences in a tabular form -:

call() Method apply() Method
1. It is used to write such a method that can be used on different objects. It is used to write methods, which can be used on different objects
2. It is a Predefined Method in Javascript. Its return value is the result of the calling function along provided this value and arguments.
3. It is used for an object to use a method that belongs to a different object. We can use a list with this function instead of the array
4. This method can also accepts parameters. This method takes parameter as an array
5.

Syntax -:

object.objectMethod.call( objectInstance, arguments )

Syntax -:

object.objectMethod.apply(objectInstance, arrayOfArguments)

Subscribe

Select Categories