Correct Method to check if a Javascript function is Exists or not

Hi everyone,

Sometime you might want to call a function in Javascript but check whether the function exists or not before calling it. You can test if a function exists in Javascript by simply testing for the name of it in an if() condition.

But Note that you can’t test for the function name by itself.
This will work but if the function doesn’t exist the Javascript will error out.

[code:js] if(some_function_name) {} [/code]

The Correct method is Like this

[code:js] if(window.some_function_name) {} [/code]

It’s a method of the window object so you need to test for window.some_function_name like so, where some_function_name is the name of the function you wish to test for.