console.log(typeof 'abc') // "string" console.log(typeof true )// "boolean" console.log(typeof {a:1}) // "object" console.log(typeof function foo(){}) ...
console.log(typeof 'abc') // "string"
console.log(typeof true )// "boolean"
console.log(typeof {a:1}) // "object"
console.log(typeof function foo(){}) // "function"
console.log(typeof undefined) // "undefined"
console.log(typeof Symbol('foo')) // "symbol" es6新增類型
// typeof 檢測數據類型,返回值是字元串
console.log(typeof 123) // 返回"number"
console.log(typeof typeof 123)// 返回時string
console.log(typeof NaN) // "number"
console.log(typeof [1,2,3])// "object"
// 判斷Array object和Object object
console.log(Array.isArray([1,2,3]))// true
console.log(Array.isArray({a:1}))// false
console.log(typeof null) // "object"
console.log(typeof class Foo{}) // "function"