ilovejsj 发表于 2013-2-7 19:35:04

关于Undefined类型字面量undefined的小小研究(1)

<html><head><title>JS</title><script type="text/javascript">//javascript中五种原始类型,分别为String,Number,Boolean,Null,Undefinedfunction test(){//Undefined类型的字面量是undefinedalert(typeof undefined);alert(typeof Undefined);alert(typeof unDefined);alert(typeof undefineD);/*四个的结果都是"undefined"因此推出undefined字面量是不区分大小写的上面这个结论是错的字面量的定义我理解为"字面量是某一种数据类型的具体表现形式"例如int型表现形式有1,2123123,695,string类型有"abc","123"等等,这些具体的表现就是这种数据类型字面量。单单从汉语的意思上也能有所理解,"字面量"就是文字表面上的表现。JavaScript中Undefined类型的字面量就只有一种就是undefined.    那么咱们现在来思考为什么上面四个结果都是undefined首先要明确一点上面的四个只有第一个才是字面量,后三个都是变量,而不是Undefined类型的字面量,在alert对话框中出现的也是Undefined类型的字面 量。通过查阅ECMA-262 5th edition【Release of the final draft ECMA-262 5th edition   (ECMAScript Language Specification) 】下载地址为:http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf第五页关于Undefined Value,Undefined Type的介绍如下4.3.9Undefined ValueThe undefined value is a primitive value used when a variable has not been assigned a value.当一个变量没有被赋值那么undefined就是他的初始值。4.3.10 Undefined TypeThe type Undefined has exactly one value, called undefined.Undefined类型有且只有一个值undefined由 4.3.9Undefined Value可知只有变量未赋值才能得到Undefined类型的字面量undefined*/}</script></head><body><input type="button"value="Click"></body></html>

总结一下:
1.Undefined类型有且只有一个字面量(值)undefined
2.当声明的变量未初始化时,该变量的默认值是undefined
一家之言,希望高手多多指教。
页: [1]
查看完整版本: 关于Undefined类型字面量undefined的小小研究(1)