×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

JavaScript & DHTML example - Is it possible to nest functions in JavaScript?


JavaScript & DHTML - Is it possible to nest functions in JavaScript?

Yes, it is. Be aware that in this case that the nested function is private to its containing function and the nested function can be accessed only with statements in the containing function. You could specify arguments for both the nested and the containing functions.
 You may take a look of the following example:
 
function container(x) 
{  
  function add(y) 
  {      
     return x+y   
  }   
 
   return add
}
 
result=container(10)(5) // will return 15

Category: JavaScript & DHTML

 
<< Go back