typeof做类型判断时容易犯下的错

学过js同学都知道js的数据类型有 

字符串、数字、布尔、Null、Undefined和object(数组、function......)

作为一个初学者我一直认为每个数据类型返回的结果是这样的

typeof("string")  

string

typeof(111)

number

typeof(true)

boolean

typeof(arr[])

Array

typeof(fn())

function

typeof(null)

null

typeof(undefind)

undefind

当我在判断nullarr[]时结果却是这样的。
typeof(arr[])

object

typeof(null)

object

以前面试被人问起我毫不犹豫的就答成上面的结果,后来测试一下才发现原来是下面这个样子的希望能和js的小伙伴们做一个共勉吧。

原文地址:https://www.cnblogs.com/pandaer/p/5080413.html