Check if the intended javascript function exist or not.

Prabhukiran345
Posted by Prabhukiran345 under CSS 3 category on | Points: 40 | Views : 1724
Often it is a best practice to call function only if exists..

So this can be achieved calling our required function in:
function fExist(f){
if(typeof f == "function"){
return f();
}
}


Test:
function foo(){
console.log("I am a function");
}

fExist(foo);


Result wil be:
TRUE

because we have defined function "foo"...

Comments or Responses

Posted by: Rajesh_Kumar on: 1/23/2014 Level:Silver | Status: [Member] [MVP] | Points: 10
Gud one :)

Login to post response