两种使用方法
typeof 操作符 用来判断变量的类型
使用: console.log(typeof(num)) 或 console.log(typeof num)
返回类型
可以返回 6 种值
-
undefined ----- 未定义的变量或值
-
boolean ------- 布尔类型的变量或值
-
string ---------- 字符串类型的变量或值
-
number -------- 数字类型的变量或值
-
obiect ---------- 对象类型的变量或值,或者null(这个是js历史遗留问题,将null作为object类型处理)
-
funcation ------- 函数类型的变量或值
typeof(typeof(a))
使用没有被定义的变量时会报错,但是在typeof中使用没有被定义的变量不会报错,会返回undefined
typeof(a)返回undefined
typeof(typeof(a))最终返回string(typeof返回值的类型是string)