查看数据类型的类型
使用
typeof obj;
返回值:"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
;
symbol
在ES2015新引入;bigint
在ES2020新引入
注意:typeof
返回值有undefined
但是没有null
,null
返回为object
查看obj是不是Obj的对象
使用
obj instanceof Obj;
返回值:true|false
注意:string 不是String,String是String
instanceof不能区别undefined和null,而且对于基本类型如果不是用new声明的则也测试不出来
使用
obj.instanceof===Object;
注意:constructor不能判断undefined和null,并且使用它是不安全的,因为contructor的指向是可以改变的
Object.prototype.toString.call(obj);//return
原文:https://www.cnblogs.com/wlxb/p/15208364.html