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
全类型都可以判断。
网友评论