分享

typeof(undefined)

 竹林湘馆 2014-11-19

1、问题:在Javascript中,typeof(undefined) == undefined成立吗?

答案:不成立,全局函数 typeof()返回值类型为字符串类型,六个可能值: "number", "string", "boolean", "object" ,"function", 和 "undefined"

只有

typeof(undefined) =="undefined";

才是成立的。

2、typeof(null) == 'undefined’成立吗?

答案:不成立,null是Object类型的数据,故typeof(null) == 'object'成立。

3、typeof([1,2]) == 'array'成立吗?

答案:不成立,typeof()返回值没有"array" 类型,同样也没有“date”类型。

4、undefined == undefined成立吗?

答案:成立。

5、null == null成立吗?

答案:成立。

6、NaN == NaN成立吗?

答案:不成立。NaN 不与任何值相等,包括其本身。要检测值是否为 NaN,请使用 isNaN 函数。

7、typeof(NaN) == 'number'成立吗?

答案:成立。NaN是属于Number类型的数据。


终上所述,null是Object类型的数据,NaN是Number类型的数据,undefined则是undefined类型的数据,即没有定义,找不到该对象或对象的属性和方法。




有关js判断undefined类型,使用typeof方法,typeof 返回的是字符串,其中就有一个是undefined。

js判断undefined类型

1
2
3
4
if (reValue== undefined)
{
alert("undefined");
}

发现判断不出来,最后查了下资料要用typeof方法:

1
2
3
4
if (typeof(reValue) == "undefined")
{
alert("undefined");
}

typeof 返回字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"。
在使用时一定要注意。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多