JavaScript判断undefined类型的正确方法

js教程评论700 views阅读模式

这篇文章主要介绍了JavaScript判断undefined类型的正确方法,相信很多同学在遇到这问题时都会用到错误的方法,正确方法也很简单,需要的朋友可以参考下

代码如下:

  if (reValue== undefined){
    alert("undefined");
    }

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

方法:

代码如下:

if (typeof(reValue) == "undefined") { 
   alert("undefined"); 
}

typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"

更多相关教程请访问 JavaScript基础教程

企鹅博客
  • 本文由 发表于 2020年1月3日 02:44:51
  • 转载请务必保留本文链接:https://www.qieseo.com/413033.html

发表评论