zoukankan      html  css  js  c++  java
  • js判断数据类型

    js里面的五种数据类型  number   string    boolean   undefined     object和函数类型 function

    js 有个方法typeof 可以判断JavaScript各种数据类型;

    typeof undefined: undefined 

    typeof '1111':string

    typeof true:boolean

    typeof 111: number

    typeof (function(){}):function

    但是有三种数据类型比较特别:

    1、typeof null :object

    2、typeof []:object

    3、typeof {}:object

    对于以上三种特殊的返回类型实在是难以区分

    以下提供一种方法来精准区分:

    object.prototype.toString.call  这个是对象的原型扩展函数,用来更精准的区分数据类型

  • 相关阅读:
    JZ-C-36
    JZ-C-35
    JZ-C-34
    JZ-C-33
    JZ-C-32
    JZ-C-31
    JZ-C-30
    JZ-C-29
    JZ-C-28
    JZ-C-27
  • 原文地址:https://www.cnblogs.com/wuhjbk/p/10653961.html
Copyright © 2011-2022 走看看