首页 > Web开发 > 详细

js数据类型

时间:2016-08-29 14:30:50      阅读:174      评论:0      收藏:0      [点我收藏+]

javascript的几种基本类型:

  1. null
  2. undefined
  3. Boolean
  4. string
  5. Number
  6. Object

我看到网上一篇文章说是typeof无法判断function,可是为什么我试验了一下是可以判断的呢?不懂,欢迎各位看到有什么问题可以留言哦

var b=function(){console.log(999);}
typeof b
"function"
Object.prototype.toString.call(b)
"[object Function]"

 array:typeof无法判断array倒确实,用Obeject.prototype.toString.call()

var a=new Array(1,2,3);
undefined
a
[1, 2, 3]
typeof a
"object"
Object.prototype.toString(a);
"[object Object]"

null:

typeof null
"object"
Object.prototype.toString.call(null)
"[object Null]"

 Date:

var a=new Date()
undefined
a
Mon Aug 29 2016 14:11:45 GMT+0800 (CST)
typeof a
"object"
Object.prototype.toString.call(a)
"[object Date]"

 HTMLCollection:

1 var a=document.getElementsByTagName(‘div‘);
2 undefined
3 Object.prototype.toString.call(a)
4 "[object HTMLCollection]"

 

js数据类型

原文:http://www.cnblogs.com/lwwen/p/5817803.html

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