javascript function call code example

Example 1: how to use function in javascript

/* Declare function */
function myFunc(param) {
  // Statements 
}

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: call function javascript

// Define your function
function sayHello(msg){
	console.log("Hello, " + msg);
}

// Call it
sayHello("Norris");

// outputs:
// Hello, Norris

Example 5: js call and apply

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

Tags:

Java Example