newPromise / js-

0 stars 0 forks source link

js 中检测类型的 typeof 方法 #10

Open newPromise opened 6 years ago

newPromise commented 6 years ago

使用 typeof 返回一个字符串,表示被检测到的数据类型

使用 typeof 数据类型:

'undefined' 'object' 'number' 'string' 'boolean' 'function ' 'symbol' 其中:

typeof null
// object
typeof Array
// object
对于 null 的检测返回的是 对象 object
对于数组的检测 返回的也是对象
因为数组是一种特殊的对象,对于数组的检测,可以使用Array.isArray() 进行判断
let arr = [];
Array.isArray(arr)
// true   使用 isArray 进行判断, arr 确实是一个数组