The main difference between call() and apply() is the way in which arguments are passed to the function.

The call() method takes arguments separately, while the apply() method takes arguments as an array.

Example:

function add(a, b) {
return a + b;
}

// call()
add.call(this, 1, 2); // Output: 3

// apply()
add.apply(this, [1, 2]); // Output: 3

Leave a Reply

Your email address will not be published. Required fields are marked *