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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题