Skip to content


How to check if a JavaScript function is defined

I encountered a small issue on javascript while doing a small hack for a VBulletin plugin. Sometimes a javascript function was included, sometimes not.
So I needed a way to check if that function was or wasn’t defined so I can call it safely (without any error message). In case you ever need something like this .. here is the code :)

JAVASCRIPT [Show Plain Code]:
  1. if(typeof functionNameToCheck == ‘function’) {
  2.         //you can now safely call your function
  3. }

Posted in Javascript Tips & Tricks.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.


Get Adobe Flash playerPlugin by wpburn.com wordpress themes