Why can I use a function before it's defined in JavaScript?

前端 未结 7 1749
日久生厌
日久生厌 2020-11-22 16:07

This code always works, even in different browsers:

function fooCheck() {
  alert(internalFoo()); // We are using internalFoo() here...

  return internalFoo         


        
7条回答
  •  死守一世寂寞
    2020-11-22 16:53

    For the same reason the following will always put foo in the global namespace:

    if (test condition) {
        var foo;
    }
    

提交回复
热议问题