DEV Community

Devi
Devi

Posted on

JS core concepts

Closures example:

The closure is a javascript nested function where we can access outerfunction variables inside the inner function by calling the innerfunction inside the outer function.

let outerfunction = ()=>{
var count = 0
let innerFunction=()=>{
count++;
console.log(count)
}
return innerFunction;
}

let increment = outerfunction()
increment();
increment();
increment();
increment();

Top comments (0)