var a = 'windowA' if (true) { var a = 'A' } function fn() { a = 'fnA' var b = 'b是局部的' c = 'c是全局的' } fn() console.log(a, b, c) //b is not defined
function parent() { var hoisted = "I'm a variable"; function hoisted() { return "I'm a function"; } return hoisted(); } console.log(parent()); //hoisted is not a function 函数提升优于变量提升
for (var i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, 1000) } console.log(i) //5 5个5