Is there a way to do functions and variable hoisting between source code present in different files? That is, something like
//Inside firstfile.js
foo === \"bar\
I originally thought this was a more interesting question than it actually appears. The answer to the question I thought this was is that each element represents a separate
Program
, each separate Program is parsed and (crucially) executed before anything happens to the next Program, therefore the effects of hoisting can only be seen within a single Program.
For example, within a single script:
... alerts "function" because the function declaration is hoisted, but splitting the two lines into separate elements changes this:
... alerts "undefined", because the first script is executed before the second script is even parsed.