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  a v a2 s . c  om*/
    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;//from ww  w.  ja v  a  2s . 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