JS中的数据类型的判断

1. typeof能判断值类型不能判断引用类型

使用typeof,能得到undefined string number boolean object function六种结果。

typeof undefined  //undefined
typeof 'abc'  //string
typeof 123 //number
typeof true //boolean
typeof {}  //object
typeof []   //object
typeof null   //object  相当于空对象
typeof console.log  //function  特殊情况,因为function是js中最重要的一种类型

2.对于引用类型的值,可以用instanceof

var a=[1,2,3]; 
a instanceof Array  

 

posted @ 2017-08-28 15:42  哼小调C  阅读(116)  评论(0)    收藏  举报