首页 > Web开发 > 详细

JS中null与undefined的区别

时间:2016-09-19 10:10:15      阅读:269      评论:0      收藏:0      [点我收藏+]

1、typeof操作符

  用来检测变量的数据类型

例:typeof 3.14  //返回number

  typeof [1,2,3]  //返回object

 

2、null

  只有一个值的特殊类型,表示一个空对象引用(可以用null来清空对象)

例:var person = null;//值为空,但类型为对象

  typeof person;  //返回object

 

3、undefined

  没有设置值的变量,(可用来清空变量、属性、和方法)

例:var person ;

  person = undefined;//值为undefined,类型也为undefined

 

4、null与undefined的区别

例:typeof undefined   //返回undefined

  typeof null       //返回object

  null === undefined  //返回false

  null == undefined    //返回true

 

JS中null与undefined的区别

原文:http://www.cnblogs.com/gosun/p/5883842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!