Using function.call to Call a Function

In JavaScript, there is a way to call a function by using the .call() method. The syntax of the .call() is as follows:

functionName.call(thisArg, arg1, arg2, ….) // arg1 and arg2 are optional


functionName: Refers to the function being called and. thisArg specifies the object that this references inside the invoked function.

Syntax

call(thisArg)
call(thisArg, arg1)
call(thisArg, arg1, /* …, */ argN)


Parameters

thisArg

The value to use as this when calling func. If the function is not in strict mode, null and undefined will be replaced with the global object, and primitive values will be converted to objects.

arg1, …, argN Optional

Arguments for the function.


Return value

The result of calling the function with the specified this value and arguments.