JavaScript tidak ditentukan
Contoh
Variabel tanpa nilai:
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";
}
Lebih banyak contoh di bawah ini.
Definisi dan Penggunaan
Properti undefined menunjukkan bahwa variabel belum diberi nilai, atau tidak dideklarasikan sama sekali.
Dukungan Peramban
undefined()
adalah fitur ECMAScript1 (ES1).
ES1 (JavaScript 1997) didukung penuh di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Lebih Banyak Contoh
Contoh
Variabel tidak dideklarasikan:
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}