如何判断 JavaScript 的数据类型?

87 阅读1分钟

判断方法 typeof

typeof 可以用来区分除了 null 类型以外的原始数据类型,对象类型的可以从普通对象里面 识别出函数:

typeof undefined // "undefined"

typeof null // "object"

typeof 1 // "number"

typeof "1" // "string"

typeof Symbol() // "symbol"

typeof function() {} // "function"

typeof {} // "object"