1.变量提升

var x = 2;

function test(){
  console.log(x)
  var x = 1;
}

==》运行程序报错,在test()函数中,x被提升到了顶部声明,相当于

var x = 2;

function test(){
    var x;
  console.log(x)
  x = 1;
}

2.函数提升

a)函数声明可以提升

test();
function test(){
  console.log(123);          
}

b)函数表达式不能提升

test();
var test = function(){
  console.log(123);          
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-08-24
  • 2021-09-06
  • 2021-12-22
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-02-11
  • 2021-10-15
相关资源
相似解决方案