首页 > 其他 > 详细

2020.11.16 typeof null undefined

时间:2020-12-24 21:21:19      阅读:31      评论:0      收藏:0      [点我收藏+]

可以使用 typeof 操作符来检测变量的数据类型。

typeof "John"                // 返回 string
typeof 3.14                  // 返回 number
typeof false                 // 返回 boolean
typeof [1,2,3,4]             // 返回 object
typeof {name:‘John‘, age:34} // 返回 object

 

null是一个只有一个值的特殊类型。表示一个空对象引用。

用 typeof 检测 null 返回是object。

var person = null;           // 值为 null(空), 但类型为对象

 

undefined 是一个没有设置值的变量。

typeof 一个没有值的变量会返回 undefined。

var person;                  // 值为 undefined(空), 类型是undefined

 

null 和 undefined 的值相等,但类型不等:

typeof undefined             // undefined
typeof null                  // object
null === undefined           // false
null == undefined            // true

 

2020.11.16 typeof null undefined

原文:https://www.cnblogs.com/SirNie/p/14159877.html

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