X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript undefined Property

Function Reference JavaScript Global Functions

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 »


Definition and Usage

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The undefined property is supported in all major browsers.


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 »


Function Reference JavaScript Global Functions

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook