javascript check if function exists

JavaScript
if (typeof sourceObj.someMethod === "function") { 
    // you are safe using the method
  	sourceObj.someMethod();
}if (typeof payment === "function")
{
  // Do something
}//check if sayHello() function exists
if (typeof sayHello === "function") { 
    // This function exists
}

Source

Also in JavaScript: