JavaScript未定義
例
値のない変数:
let x;
if (x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
let x;
if (typeof x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
以下のその他の例。
定義と使用法
undefinedプロパティは、変数に値が割り当てられていないか、まったく宣言されていないことを示します。
ブラウザのサポート
undefined()
ECMAScript1(ES1)機能です。
ES1(JavaScript 1997)は、すべてのブラウザーで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
その他の例
例
宣言されていない変数:
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}