A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment).

In other words, a closure gives you access to an outer function’s scope from an inner function.

Untitled

Untitled

const text = 'hello';
function func(){
    console.log(text);
}
func();

function outer(){
    const x = 0;
    function inner(){
        console.log(`inside inner: ${x}`);
    }
    return inner;
}
const func1 = outer();
func1(); // inside inner: 0

1) closure 활용예제

2) quiz