-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
Closures are not supported in all programming languages, but they are in Javascript. It seems to understand them, it is necessary to look at three facts about closures.
This is the second one and the others can be found here:
Fact two says that a variable which is defined in an outer function can be refered and ultimately used by inner functions even after the outer function has already returned. For example
function anyOutsideFunction()
{
var varOutside = "Hello";
function anyInsideFunction(anyVariable)
{
return varOutside + " " + anyVariable;
}
return anyInsideFunction;
}
var Hello = anyOutsideFunction();
console.log(Hello("World!"));//Outputs "Hello World!"The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

The essential part of the program relevant to fact two is found in "closures.js".
The colored areas are just for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman