美文网首页
js判断类型

js判断类型

作者: AlinaMay | 来源:发表于2021-07-16 17:21 被阅读0次

1、typeof

检测不出null 和 数组,结果都为object,所以typeof常用于检测基本类型;

2、instanceof

不能检测出number、boolean、string、undefined、null、symbol类型,所以instancof常用于检测复杂类型以及级成关系;

3、constructornull、undefined没有construstor方法,因此constructor不能判断undefined和null

但是contructor的指向是可以被改变,所以不安全;

4、Object.prototype.toString.call

全类型都可以判断。

相关文章

网友评论

      本文标题:js判断类型

      本文链接:https://www.haomeiwen.com/subject/tzubpltx.html