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 // false
typeof(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方法
最全的判断方式:
Object.prototype.toString.call()

本文深入探讨了JavaScript中的typeof操作符,它用于确定变量的数据类型。特别地,`typeof null`返回object,而`typeof undefined`返回undefined。文章还列举了其他基本数据类型的typeof结果,如number、string、boolean等,并介绍了如何使用`Array.isArray()`和`instanceof`来判断数组。此外,提到了`Object.prototype.toString.call()`作为全面判断数据类型的方法。
1633

被折叠的 条评论
为什么被折叠?



