typeof(undefined) // "undefined"typeof(null) // "object"typeof([1,2]) // "object"typeof({a:1}) // "object"typeof('123') // "string"typeof(1) // "number"typeof(true) // "boolean"typeof(Array) // "function"typeof(() => {}) // typeof 箭头函数返回也是 "function"
谨记typeof的返回值都是 string类型
typeof(typeof(null)) // "string"typeof(typeof(undefined)) // "string"typeof(undefined) === undefined // falsetypeof(undefined) === "undefined" // true
特别的: null返回的是”object” ,undefined返回还是”undefined” typeof 可以返回的类型为:number、string、boolean、undefined、object、function
判断数据是否是数组类型:
arr = []arr instanceof Array // instanceof判断方法Array.prototype.isPrototypeOf(arr) // 原型链判断Array.isArray(arr) // JS 数组方法Array中的isArray方法
原文链接:https://blog.csdn.net/qq_41860203/article/details/112602154
