六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 108|回复: 0

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

[复制链接]

升级  21.33%

22

主题

22

主题

22

主题

秀才

Rank: 2

积分
82
 楼主| 发表于 2013-2-7 19:35:04 | 显示全部楼层 |阅读模式
<html><head><title>JS</title><script type="text/javascript">//javascript中五种原始类型,分别为String,Number,Boolean,Null,Undefinedfunction test(){  //Undefined类型的字面量是undefined  alert(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.9  Undefined Value  The undefined value is a primitive value used when a variable has not been assigned a value.  当一个变量没有被赋值那么undefined就是他的初始值。  4.3.10 Undefined Type  The type Undefined has exactly one value, called undefined.  Undefined类型有且只有一个值undefined  由 4.3.9  Undefined Value可知只有变量未赋值才能得到Undefined类型的字面量undefined  */}</script></head><body><input type="button"  value="Click"></body></html>

  总结一下:
  1.Undefined类型有且只有一个字面量(值)undefined
  2.当声明的变量未初始化时,该变量的默认值是undefined
  一家之言,希望高手多多指教。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表