[javascript] How to tell if a JavaScript function is defined

Most if not all previous answers have side effects to invoke the function

here best practice

you have function

_x000D_
_x000D_
function myFunction() {_x000D_
        var x=1;_x000D_
    }
_x000D_
_x000D_
_x000D_ direct way to test for it

_x000D_
_x000D_
//direct way_x000D_
        if( (typeof window.myFunction)=='function')_x000D_
            alert('myFunction is function')_x000D_
        else_x000D_
            alert('myFunction is not defined');
_x000D_
_x000D_
_x000D_ using a string so you can have only one place to define function name

_x000D_
_x000D_
//byString_x000D_
        var strFunctionName='myFunction'_x000D_
        if( (typeof window[strFunctionName])=='function')_x000D_
            alert(s+' is function');_x000D_
        else_x000D_
            alert(s+' is not defined');
_x000D_
_x000D_
_x000D_