undefined为什么是字符串类型的

var x;
console.log(x);                    //undefined
console.log(typeof x);            //undefined;
console.log(typeof typeof x)      //string

//还有,为什么typeof 非得转两次才能转成成字符串?
阅读 6k
5 个回答

typeof x === 'undefined'

typeof typeof x相当于typeof 'undefined'

typeof 任何东西得到的都是字符串。

typeof obj 返回的结果是string 类型。
undefined 不是string类型

  typeof 111 //"number"
  typeof  typeof 1 //"string"  实际判断的是typeof 1 返回结果的类型

注意看undefined的颜色不一样,此undefined非彼undefined
typeof undefined

推荐问题