Check if a Javascript Function Exists or Is Defined

It’s always frustrating when you get an error trying to call a function that hasn’t been defined but there’s an easy way  to prevent this. To check if a Javascript function exists before calling it, try this:

if (typeof yourFunctionName == 'function')

Here are some related stories you may also be interested in:

Also, check out Publishing with WordPress, it’s full of useful and timely WordPress guides,  or follow me on Twitter @reifman.

Bloggers: WP Engine has increased their referral payments to $200 each! Try out their WordPress hosting.