JavaScript undefined Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript undefined Property

❮ JavaScript Global Functions

Example

Test if a variable is undefined:

var x;

if (x === undefined) {
    txt = "x is undefined";
} else {
    txt = "x is defined";
}
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

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


Browser Support

Property
undefined Yes Yes Yes Yes Yes


Technical Details

JavaScript Version: ECMAScript 1

More Examples

Example

Test if variables are undefined:

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;
Try it Yourself »

❮ JavaScript Global Functions