JavaScript undefined Property
Example
Test if a variable is undefined:
var x;
if (x === undefined) {
txt = "x is
undefined";
} else {
txt = "x is defined";
}
The result of txt will be:
x is undefined
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: | 1.3 |
---|
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;
The result of txt will be:
t1 is defined
t2 is undefined
Try it yourself »
JavaScript Global Functions