[Javascript]js判断是否为undefined类型

概述

在项目获取某个元素的值会出现undefined,所以对这种情况要有特殊处理。

可通过下面的代码判断是否为undefined类型。

1 if (typeof(reValue) == "undefined") { 
2    alert("undefined"); 
3 }  
4 
5 typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"

总结

发现有那么段时间没大量的使用js了,有些生疏了。看来得抽出点时间,复习一下了。

原文地址:https://www.cnblogs.com/wolf-sun/p/3969468.html