在JavaScript中测试变量是否未定义的最合适方法是什么?我见过几种可能的方法:
if (window.myVariable)
Run Code Online (Sandbox Code Playgroud)
要么
if (typeof(myVariable) != "undefined")
Run Code Online (Sandbox Code Playgroud)
要么
if (myVariable) //This throws an error if undefined. Should this be in Try/Catch?
Run Code Online (Sandbox Code Playgroud) 我一直以为我可以通过比较未定义的var来检查未定义的var,但这是我在chrome控制台中得到的错误:

我如何检查jQuery未定义的对象?
编辑:

if(jQuery)也给我带来了问题
编辑:
方案:
if(window.jQuery)作品.
typeof(jQuery) == 'undefined'也有效.
谁有人解释为什么?