undefined

王朝百科·作者佚名  2010-04-18  
宽屏版  字体: |||超大  

undefined

可用性

用法

undefined

参数

无。

返回

无。

说明

一个特殊值,通常用于指示变量尚未赋值。对未定义值的引用返回特殊值 undefined。动作脚本代码 typeof(undefined) 返回字符串 "undefined"。undefined 类型的唯一值是 undefined。

当将 undefined 转换为字符串时,它转换为空字符串。

undefined 值与特殊值 null 相似。事实上,当使用相等运算符对 null 和 undefined 进行比较时,它们的比较结果为相等。

示例

在这个示例中,变量 x 尚未声明,所以其值为 undefined。在代码的第一部分,使用相等运算符 (==) 比较 x 的值与值 undefined,并将相应的结果发送到输出窗口。在代码的第二部分,使用相等运算符比较值 null 与 undefined。

// x has not been declared

trace ("The value of x is " + x);

if (x == undefined) {

trace ("x is undefined");

} else {

trace ("x is not undefined");

}

trace ("typeof (x) is " + typeof (x));

if (null == undefined) {

trace ("null and undefined are equal");

} else {

trace ("null and undefined are not equal");

}

下面的结果显示在输出窗口中:

The value of x is x is undefined

typeof (x) is undefined

null and undefined are equal

注意:在 ECMA-262 规范中,将 undefined 转换为字符串“undefined”,而不转换为空字符串。这是动作脚本与 ECMA-262 规范之间的差异。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有