zoukankan      html  css  js  c++  java
  • var、fucntion关键字优先级问题

    情况1:使用var关键字定义的变量优先被声明

    console.log(a);      // undefined

    var a = 20;

    /*

      var a =20;

        (1)声明变量a --  优先被执行,此刻的值是undefined

        (2)给变量a赋值,等赋值语句执行,进行赋值,此刻的值是20

    */

     

    情况2:使用fucntion关键字定义的函数,优先被执行

    var test = 20;

    function test(){

      console.log("I can fly");

    }

    test();      // test is not a fucntion

    /*

    执行过程:(1)var优先声明,声明变量test,此刻test的值为undefined

         (2)function优先定义,此刻test变为一个函数

         (3)程序顺序执行,test = 20,执行赋值操作,test变量由函数变成了数值类型

    */

     

  • 相关阅读:
    php函数、php定义数组和数组遍历
    php语句
    php基础
    phpcms 标题设置
    上传头像预览
    简单的轮播样式
    ajax 小练习
    生成地图
    php注释规范
    thinkphp 实现分页
  • 原文地址:https://www.cnblogs.com/sherryStudy/p/priority.html
Copyright © 2011-2022 走看看