在栈内存中,后进先出
<script> console.log('gb:' + i) var i = 1 foo(1) function foo(i) { if (i == 4) { return } console.log('fb:' + i) foo(i + 1) console.log('fe:' + i) } console.log('ge:' + i) </script>
输出
声明提升
案例1
function a() {} var a; console.log(typeof a) // function
案例2
if (!(b in window)) { var b = 1 } console.log(b) // undefineda
案例3
var c = 1 function c(c) { console.log(c) var c = 3 } c(2) // 报错 Uncaught TypeError: c is not a function