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)

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay