The undefined type indicates that a variable has not been assigned a value.
The undefined type indicates that a variable has not been assigned a value.
Test if a variable is undefined:
var x; if (x === undefined) { txt = "x is undefined"; } else {/*from w w w. j av a 2s . c o m*/ txt = "x is defined"; } console.log(txt);
Test if variables are undefined:
//check whether the variables have been assigned a value or not. var t1 = "myVar"; var t2;/* w ww . j a v a 2 s. c o m*/ 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 + "\n" + txt2; console.log(txt);