check if function exists code example

Example 1: javascript check if function exists

//check if sayHello() function exists
if (typeof sayHello === "function") { 
    // This function exists
}

Example 2: check if function exists javascript

if (typeof payment === "function")
{
  // Do something
}

Example 3: javascript check if function exists

if (typeof sourceObj.someMethod === "function") { 
    // you are safe using the method
  	sourceObj.someMethod();
}

Example 4: js check if function exists

if (typeof yourFunctionName == 'function') { 
  yourFunctionName(); 
}

Tags:

Php Example