js判断undefined类型
2015-08-28 17:59
585 查看
最近写js的时候遇到undefined的情况,按照网上搜的结果大家一致都在用下面的方法来判断
if (typeof(reValue) == "undefined") {alert("undefined");
}
但是这种方法在调试的时候并不管用。调试发现 typeof(reValue)得到的结果是string(在firefox和chrom中使用firebug调试),所以有必要在原来的基础上再加上一个判断
正确的做法是:
if (typeof(reValue) == "undefined" || reValue == "undefined"){
alert("undefined ");
}
这样做就可以避免typeof(reValue)得倒结果为string的情况了。
相关文章推荐
- js字符串的各种格式的转换 ToString,Format
- 译:Grunt编译sass&compass和压缩js的工作流程
- JFinal+JS向后台传递数组的方法
- js跨域及解决方案
- JS实现颜色值的转换
- ExtJs计算两个DateField所间隔的月份(天数) new Date(str) IE游览器提示NaN 处理
- js 跨域问题常见的五种解决方式
- Javascript中的this关键字
- 迷你MVVM框架 avalonjs 入门教程
- 纯JavaScript实现一些小功能
- 谷歌地图鼠标绘制多边形方法
- 【JavaScript基础知识】——面向对象和原型
- javascript中的函数Function
- 如何成为一个优秀的开发者
- json文件格式
- 两次调用encodeURI来解决乱码问题
- js 处理 ie和firefox window.frames 兼容问题
- exportjson2cpp 使用(coco2dx json文件转CPP)
- JS正则表达式大全(整理详细且实用)
- javascript操作表单