Sunday, November 4, 2012

Important difference between 'function statements' and 'function expressions' in Javascript

EXAMPLE 1 - select the "RESULT" tab to execute the code
When the below code runs, "Yes" is printed, but not "No".
The reason is - before the code runs, "function statements" are interpreted and added to the execution stack/context, but the same is not done for "function expressions"
(Book - JavaScript Succinctly, Pg 102)

Therefore, the order in which functions are invoked & defined, becomes important when using "function expressions"
(Have to read more about this)


EXAMPLE  2 - using jQuery - $(document).ready()
Click on "RESULT" to see the result

No comments:

Post a Comment

Followers

Blog Archive