call and apply in javascript code example

Example 1: apply() js

The apply() method accepts arguments in an array:

var arr = [6, 89, 3, 45];
var maximus = Math.max.apply(null, arr); // returns 89

Example 2: running a function in a function javascript

function runFunction() {
  myFunction();
}

function myFunction() {
  alert("runFunction made me run");
}

runFunction();

Example 3: javascript function call with variable

function abc() {
  alert('test');
}

var funcName = 'abc';

window[funcName]();

Example 4: js call and apply

func.call([thisArg[, arg1, arg2, ...argN]])