Home arrow JavaScript arrow Page 3 - Scope of Variables and Arguments in Nested JavaScript Functions
JAVASCRIPT

Scope of Variables and Arguments in Nested JavaScript Functions


In this part of the series we shall look at the scope of variables and arguments in nested functions. We shall see whether the outer function can use the variables and arguments of the inner functions and vice versa. We shall also see how many levels downward or upward this can be done.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
October 15, 2009
TABLE OF CONTENTS:
  1. · Scope of Variables and Arguments in Nested JavaScript Functions
  2. · Argument Scope within Nested Functions
  3. · Function Call, Argument and Variable Scope Summary
  4. · Passing Arguments to Inner Functions from Outside

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Scope of Variables and Arguments in Nested JavaScript Functions - Function Call, Argument and Variable Scope Summary
(Page 3 of 4 )

We conclude that a function can call its immediate nested function, but it cannot call a function that is more than one level down (inner). However, any nested function can call its nesting (outer) function or any of its ancestor outer functions.

Independent of the level of the inner function, an outer function cannot use the variables of an inner function. Even though an outer function can call its immediate inner function, an outer function cannot use the variables of its immediate inner function.

Independent of the level of the inner function, an outer function cannot use the arguments of the inner function. Even though an outer function can call its immediate inner function, an outer function cannot use the arguments of its immediate inner function.

Independent of the level of the outer function, an inner function can use the variables of the outer function. Independent of the level of the outer function, the inner function can use the arguments of the outer function.

Calls Within the Set of Functions

As we have seen, functions can be calling one another within the set. However, watch out for unending loops. You should use nested functions instead of independent functions when you are looking for something like a small module. In this module situation, you would call the outermost function; the set of nested functions will carry out the task, and then only return the result. It is the outermost function that has to return the result.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials