Wednesday, June 4, 2014

JavaScript Scope: Function Evaluation


Function declarations are evaluated first and moved to the top of the scope during parsing. So, you can declare them anywhere in the body of the script and call them before the declaration:


Function expressions are not evaluated until assignment:


Like other variables, it is a good idea to define them at the top of the scope. But, with function expressions you must make the assignment before you make a call:


To sum it all up, take a look at the Locals window when execution starts:


The declared functions are evaluated and ready for calls as soon as script execution starts. 

No comments:

Post a Comment