zoukankan      html  css  js  c++  java
  • undefined 与 xx is not defined 的区别

    undefined 与 xx is not defined 的区别

      1. undefined 表示是javascript中的一种数据类型,当被定义的变量没有被赋值或者某个被调用的函数没有定义返回值时候会产生。

      2. xx is not defined 是一种语法错误,表示xx变量没有被定义。

      例1:undefined示例

        代码:

    1 console.log(num);
    2 var num ;    //定义了全部变量num,但是没有初始化赋值

        运行结果:

         

      例2:xx is not defined 示例

        代码:

    1 console.log(num);  //变量 num 未被定义
    2 //var num ;    

        运行结果:

          

      例3:undefined 示例

        代码:

    1 function testFuc (){
    2     var num = 0;
    3     num = num+1;
    4 }
    5 
    6 console.log(testFuc());

        运行结果:

          

    说明:

      【js代码的执行顺序问题】
        js代码在运行时,会分为两大部分。检查装载和执行阶段。

          检查装载阶段:会先检测代码的语法错误,进行变量、函数的声明

          执行阶段:变量的赋值、函数的调用等,都属于执行阶段。

          

  • 相关阅读:
    【HDU2222】Keywords Search(AC自动机)
    -网络流题表
    【 POJ
    【 UVALive
    【POJ2699】The Maximum Number of Strong Kings(网络流)
    【UVALive
    【HDU3081】Marriage Match II (二分+最大流)
    【UVALive
    【LA2796】Concert Hall Scheduling(最大费用最大流)
    【 UVALive
  • 原文地址:https://www.cnblogs.com/mycnblogs-guoguo/p/10430836.html
Copyright © 2011-2022 走看看