2 ms·
Javascript solves this with function hoisting. In simplified terms you do two compiler passes, once for global symbols and once for linear execution. After all
by wongarsu 3y ago
Javascript solves this with function hoisting. In simplified terms you do two compiler passes, once for global symbols and once for linear execution.
After all nothing stops you from writing in your language definition that defining a function anywhere in the file is the same as defining it in the beginning, and then you can treat it as if the entire file was in a main function, except for functions and the declaration of global variables.