例
测试一个变量是不确定的:
var x;
if (x === undefined) {
txt = "x is
undefined";
} else {
txt = "x is defined";
}
TXT的结果将是:
x is undefined
试一试» 更多"Try it Yourself"下面的例子。
定义和用法
未定义属性指示变量尚未赋值。
浏览器支持
属性 | |||||
---|---|---|---|---|---|
undefined | 是 | 是 | 是 | 是 | 是 |
技术细节
JavaScript的版本: | 1.3 |
---|
更多示例
例
测试如果变量是不确定的:
var t1 = "myVar";
// defined
var t2;
// undefined
if (t1 === undefined) {
txt1 = "t1 is undefined";
} else {
txt1 = "t1 is
defined";
}
if (t2
=== undefined) {
txt2 = "t2 is undefined";
} else {
txt2 = "t2 is defined";
}
txt = txt1 + "<br>" + txt2;
TXT的结果将是:
t1 is defined
t2 is undefined
试一试» <JavaScript的全局函数