The difference between call and apply is as follows:-
When you use apply it lets you invoke the function with arguments as an array; and when you use call it requires the parameters to be listed explicitly.
Syntax for the apply and call is as follows:-
theFunction.apply(valueForThis, arrayOfArgs)
theFunction.call(valueForThis, arg1, arg2, ...)
You can see the example code below:
function theFunction(name, profession) {
console.log("My name is " + name + " and I am a " + profession +".");
}
theFunction("Hari", "driver");
theFunction.apply(undefined, ["rahul", "engineer"]); theFunction.call(undefined, "joe", "doctor"); theFunction.call(undefined, ...["ravi", "chemist"]);