DEV Community

Vishnu Priya S
Vishnu Priya S

Posted on

Closure

Data privacy & Encapulsation

-> It creates a private variable that cannot be accessed or modified directly from outside.

-> It gives a inner function access to the outer function and after that the outer function has finished executing.

eg:
function bank(){
let count = 0;
return function(){
count++;
};}
const counter = bank();
console.log(counter()); // 1

Top comments (0)