/*
* A closure is a function that retains 
* access to its lexial scope, even when 
* is executed outisite of that scope.
* Lexical Scope: Is the definition area 
* of an expresion.
* 
* A closure is a function that remembers the
* variables from the place where its defined,
* regardless of where it is executed later
*/

function function1() {    
    function inner(value = 0) {
        value += 10;
        console.log(value);
    }
    
    return inner;
}

function function2() {
    let value = 0;

    function inner() {
        value += 10;
        console.log(value);
    }
    
    return inner;
}

[function1, function2].forEach(fn => {
    console.log("----------- ", fn.name, " ----------- ")
    const inner = fn();
    Array.from({length: 5}).forEach(() => inner())
});

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: