How to check if a javascript function exists or is defined?

To check if a Javascript function exists before calling it, try this:

if(typeof functionName == 'function')

If you want to reduce the number of strings hanging around in your code, try this instead

if (typeof(possibleFunction) == typeof(Function))

Leave a Reply

Your email address will not be published. Required fields are marked *