目录
Object.prototype.toString.call()
Number.isNaN/Number.isInfinity/Number.isInteger
typeof()
可以传入未经定义直接使用的变量,能区分并返回字符串数据类型undefined、boolean、number、string、function、object(null属于object)、symbol。
A instanceof B
判断A对象的原型链(__proto__)上有没有B的原型(prototype),返回true或false。
注意B只能为函数,不能为对象,否则会报错。
例如[] instanceof Array返回true,因为[].__proto__=Array.prototype。
object.constructor
Array/String/Boolean/Object/Function以及申明函数和对象的__proto__、prototype和constructor属性的指向问题_AIWWY的博客-CSDN博客
Object.prototype.toString.call()
能区分系统设定好的所有构造函数(大写字母开头的函数)构造的对象,返回字符串模式的[object 构造函数名],包括Boolean、Number、String、Function、Object、Math、RegExp、Array、Date等
其中还区分null、undefined,返回首字母为大写的字符串形式的[object Null]、[object Undefined]。
jQuery.type()
返回任意数据类型,以全小写字符串形式(‘object’、‘null’、‘undefined’等)返回。
其它
Number.isNaN/Number.isInfinity/Number.isInteger
JavaScript的7种数据类型以及隐式类型转换_AIWWY的博客-CSDN博客