Javascript - Global undefined type

The undefined type indicates that a variable has not been assigned a value.

Description

The undefined type indicates that a variable has not been assigned a value.

Example

Test if a variable is undefined:

Demo

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);

Result

Test if variables are undefined:

Demo

//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);

Result