【问题标题】:JS: difference between undefined and `undefined`JS:未定义和`未定义`之间的区别
【发布时间】:2015-06-15 21:38:31
【问题描述】:

查看这段代码;为什么不满足(a === typeof a)

var a;
(a === undefined)?console.log("a is undefined"):null;
(typeof a === 'undefined')?console.log("typeof a is 'undefined'"):null;

【问题讨论】:

    标签: javascript undefined typeof


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      因为:

      var a;
      typeof a === 'undefined';
      a === undefined;
      

      一个是字符串值为'undefined' 的字符串,一个是undefined 原语。这两个不一样。

      typeof x 总是返回字符串值,例如"undefined""boolean""string""object" 等......

      【讨论】:

        猜你喜欢
        • 2011-03-26
        • 2012-07-28
        • 1970-01-01
        • 2023-03-15
        • 1970-01-01
        • 2011-07-03
        • 2016-09-02
        • 1970-01-01
        • 2011-07-21
        相关资源
        最近更新 更多