强制类型转换 被诟病为 设计语言的缺陷
内置类型(7)
null undefined number boolean string object symbol
基本数据类型
typeof 查看 类型 字符串值
null JSbug
typeof null === 'object'
typeof function a(){} === 'function'
函数
函数是JS内置类型,为 object 子类型 函数不仅是对象还可以拥有属性 function a(b,c,d){} 函数 length 属性是其声明的参数个数 a.length === 3
数组
数组不是一个特殊的类型,数组为对象,也是object的子类型
值,类型
JS 变量没有类型,只有值才有 变量可以随时持有任何类型的值
typeof 返回变量持有类型的值
undefined undeclared
在 JS 里面 未定义 未声明 是完全不同的概念
声明 没有赋值 undefined 作用域中没有声明 undeclared
typeof 对于未定义 未声明 返回值都为 undefined
使用 typeof 来检测一个变量 if (typeof a !== 'undefined') { // 同时检测值未定义,未声明 console.log('检测是否有值') }