Fri, 17 May 2024


Javascript Example: Is it possible to nest functions in JavaScript?

By: Anton, NetArt Media
Fri, 15 January 2021

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
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox