10011---JavaScript--typeof,null,undefined
2015-12-12 00:13
585 查看
typeof 操作符
你可以使用 typeof 操作符来检测变量的数据类型。typeof "John" // 返回 string typeof 3.14 // 返回 number typeof false // 返回 boolean typeof [1,2,3,4] // 返回 object typeof {name:'John', age:34} // 返回 object注:在JavaScript中,数组是一种特殊的对象类型。 因此 typeof [1,2,3,4] 返回 object。
Null
在 JavaScript 中 null 表示 "什么都没有"。null是一个只有一个值的特殊类型。表示一个空对象引用。typeof null // 返回 object你可以设置为 null 或 undefined 来清空对象:
var person = null; // Value is null, but type is still an objectvar person = undefined; // 值为 undefined, type is undefined
Undefined
在 JavaScript 中, undefined 是一个没有设置值的变量。typeof 一个没有值的变量会返回 undefined。var person; // Value is undefined, type is undefinedtypeof person // 返回undefined
Undefined 和 Null 的区别
typeof undefined // undefinedtypeof null // objectnull === undefined // falsenull == undefined // true
相关文章推荐
- JSP实现屏蔽浏览器缓存的方法
- JavaScript匿名函数之模仿块级作用域
- javascript性能优化之事件委托实例详解
- JavaScript文档碎片操作实例分析
- javascript性能优化之DOM交互操作实例分析
- ExtJS5的grid filter改造
- 符合Ext tree的全国城市列表json格式
- 支持导航滚动的Extjs实现
- 使用json取代传统的form提交
- Ext(www.extjs.com)使用感受
- Ext的form类型扩展(一)——TreeField
- 解决js对象的深度clone导致的递归死循环
- 微博@输入功能的ExtJS实现
- JSP容器下session失效的几种情况及应对
- js push string in array
- js----Date
- 10010---JavaScript--switch,for/in,while
- bz 1029: [JSOI2007]建筑抢修
- js--------String
- Javascript重要知识点梳理