JavaScript undefined Property

Definition and Usage

undefined Properties indicate that the variable has not been assigned a value, or it has not been declared at all.

Instance

Example 1

Test if a variable is undefined:

var x;
if (typeof x === "undefined") {
  txt = "x is undefined";
} else {
  txt = "x is defined";
}

Try it yourself

Example 2

Test if an undeclared variable is undefined:

if (typeof y === "undefined") {
  txt = "y is undefined";
} else {
  txt = "y is defined";
}

Try it yourself

Technical Details

JavaScript Version: ECMAScript 1

Browser Support

Properties Chrome Edge Firefox Safari Opera
undefined Support Support Support Support Support