有三种判断方式,如下图代码贴出。

<script type="text/javascript">
    var t;
    if (t === undefined) {
        alert("t is undefined1")
    }
    if (t == undefined) {
        alert("t is undefined3")
    }
    if (typeof (t) == "undefined") {
        alert("t is undefined2")
    }
    //如果t被声明但是未赋值,三次弹出均有效
    //如果t未被声明,前两个个方法会报错,注释前两个方法,方法三弹出有效
    //所以 判断undefined尽量使用方法三
</script>



相关文章:

  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-20
  • 2021-11-09
  • 2021-06-02
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-10-02
相关资源
相似解决方案