typefo也是运算符,是用来计算值的类型的
typeof一个变量时的结果是6个字符串:"number" "string" "undefined" "boolean" "object" "function"
如下图所示
var a = 1
var b = "1"
var c = undefined
var d = true
var e = null
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);
console.log(typeof d);
console.log(typeof e);
而当typeof检查一个值是否为函数时,typeof的返回值为function
因为typeof运算的结果是六个字符串,所以typeof一个typeof的值时,得到的永远都是字符串“string”。
var a = true
console.log(typeof a);
var b = typeof a
console.log(typeof b);
var c = typeof b
console.log(c);