var a;
typeof(a);
//undefined
typeof(c);
//undefined
if(c) {}
//throw error
我怎么知道c没有try catch.
标记重复后更新:
typeof initializedVariable两者typeof notInitializedVariable都将显示“未定义”。我的问题是知道变量是否存在(初始化)。
var a;
typeof(a);
//undefined
typeof(c);
//undefined
if(c) {}
//throw error
我怎么知道c没有try catch.
标记重复后更新:
typeof initializedVariable两者typeof notInitializedVariable都将显示“未定义”。我的问题是知道变量是否存在(初始化)。
您可以使用typeof运算符。
if (typeof a === 'undefined') {
// variable is undefined
}