tutorial pengembangan web terbaru
 

JavaScript undefined Property

<Fungsi JavaScript global

Contoh

Uji jika variabel tidak terdefinisi:

var x;

if (x === undefined) {
    txt = "x is undefined";
} else {
    txt = "x is defined";
}

Hasil txt akan:

x is undefined
Cobalah sendiri "

Lebih "Try it Yourself" contoh di bawah ini.


Definisi dan Penggunaan

Properti terdefinisi menunjukkan bahwa variabel belum ditetapkan nilai.


Dukungan Browser

Milik
undefined iya nih iya nih iya nih iya nih iya nih

Rincian teknis

Versi JavaScript: 1.3

contoh

Contoh lebih

Contoh

Uji apakah variabel terdefinisi:

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;

Hasil txt akan:

t1 is defined
t2 is undefined
Cobalah sendiri "

<Fungsi JavaScript global