在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)