Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

踩坑记--变量提升

js执行过程分为2部分词法分析、执行代码

易错点分析变量提升
    console.log(a);  //undefined
    var a = 123; 
//---------------等同于--------------------
    var a;
    console.log(a)
    a = 123
//----------------进阶-------------------------
    console.log(v1);
    var v1 = 100;
    function foo() {
      console.log(v1);
      var v1 = 200;
      console.log(v1);
      }
    foo();
    console.log(v1);
易错点分析函数提升
bar() 
var bar = function() {  //函数表达式式声明
  console.log(1);
}
//-----------等同于-----------------
var bar;
bar()  // 只是声明了,并未表明是函数类型,所以无法执行
bar = function(){ ... }
是不是认为函数提升就一定不会执行成功??

函数字面量式声明,可以提升并执行

//函数字面量声明式
function bar () {}
//变量形式声明; 
var foo = function () {}
posted @ 2020-11-23 22:33  365/24/60  阅读(83)  评论(0编辑  收藏  举报