JavaScript undefined 属性

定义和用法

undefined 属性表示变量没有被赋值,或者根本没有被声明。

实例

例子 1

测试变量是否未定义:

var x;

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

亲自试一试

例子 2

测试未声明的变量是否未定义:

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

亲自试一试

技术细节

JavaScript 版本:ECMAScript 1

浏览器支持

属性ChromeEdgeFirefoxSafariOpera
undefined支持支持支持支持支持