例
測試一個變量是不確定的:
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的全局函數