关于js中的类型内容总结(类型识别)

JS 有7种数据类型:

    6种原始类型:Boollean    String   Number    Null    Underfined   Symbol

    引用类型:Object

类型识别主要有以下四种方法:

  typeof    insatanceof    Object.prototype.toString().call    constructor 

一、typeof操作符

  其可以识别标准类型(Null除外)不可以识别具体的对象类型(function除外)

例子如下:

 

 

 

 

 

 

 

 

 

 

 

 

二、instanceof

  instanceof可以判别内置对象类型、可以判别自定义对象类型、不可以判别原始类型

 

三、Object.prototype.toString().call

四、constructor

  

posted @ 2015-12-18 10:50  myherodream  阅读(161)  评论(0编辑  收藏  举报