function t() {
    if(typeof(arguments[0]) === undefined){
        alert(true);
    }
}
这里的undefined需要用单引号括起来吗?ex:'undefined'
还有其他类型:number、function、string、null、boolean都是要单引号括起来?
我看网上有些是有加引号的,有些又没有,一时就迷茫了。
js

解决方案 »

  1.   

    var aa = {};
    if(typeof aa == "undefined")
    if(aa == undefined)
    if(aa === undefined)上面3种都行
      

  2.   

    我觉得判断undefined不用typeof,直接
    if(aa === undefined)
    好了,jslint也是不推荐比较undefined时用typeof的。
      

  3.   

    除了undefined类型,其他的都需要用typeof吗?
      

  4.   

    null也不需要用typeof,其他的几类建议还是用typeof比较好。
      

  5.   

    typeof 返回 是字符串类型 所以加上引号做字符串间对比