js数据类型分为:
基本类型: number boolean string null undefined symbol
(1) typeof
输出: number boolean string object function undefined
typeof null => object
typeof [] => object
基本类型: number boolean string null undefined symbol
复杂类型: object
(1) typeof
输出: number boolean string object function undefined
typeof null => object
typeof [] => object
typeof返回的都是字符串类型
var a = 'wott'
var b = new String('wott')
typeof a => string
typeof b => object
(2) instanceof
object instanceof constructor 表述:instanceof运算符用来检测constructor.prototype是否存在于参数object的原型链上。
var c = [1,2,3]
c instanceof Array => true
______________________________________
var a = 'watt'
var b = new String('watt')
a instanceof String => false
b instanceof String => true
(3) constructor判断
c.constructor === Array => true
d.constructor === Data => true
但是继承时会出错
function A(){}
function B(){}
A.prototype = new B()
var aObj = new A()
aObj.constructor === B
(4) prototype判断
Object.prototype.toString.call(a) === '[Object String]'
Object.prototype.toString.call(c) === '[Object Array]'
类型转换
函数