js数据类型的判断

1 篇文章 0 订阅

js基本数据类型:boolean、null 、 underfined 、 string、number

引用类型:date、array、object、function

 

1、typeof判断。

适合判断基本数据类型: eg:let x = "123"; console.log(typeof x) ; string 

 判断引用类型的时候: eg : let x = [1,2]; console.log(typeof x); object 

                                           let y = new Function(); console.log(typeof y); function

 

2、instanceof判断

适合判断引用类型: eg :let x = [1,2]; console.log(x instanceof Array) ; true 

 

3、constructor判断

     eg:let  x =[1,2] ;console.log(x.constructor === Array); true;

  问题:function A (){};function B(){}; B.prototype = new A();   let x = new B(); console.log(x.constrcotor==A) ;true

                                                                                                                            console.log(x.constrctor==B);false

4、Object.proptotype.toString.call()判断

eg:let x = "123";console.log(Object.prototpye.toString.call(x)=="[object string]");true;

5、jQuery.type()判断

eg:let x  =  new date();console.log(jQuery.type(x));Date();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值