Closure in JavaScript
Samrat
Posted on August 31, 2023
Closure is nothing but a technique bringing out the variable to the outer scope so that parent scope can also work with the variable from child scope.
function foo(){
let count = 0;
return function(){
return count+=1;
}}
let doo = foo();
console.log(doo());
console.log(doo());
console.log(doo());
console.log(count);
Here count
variable can be mutated from the outer scope.
But count
variable cannot be accessed directly from outside the foo
function.
💖 💪 🙅 🚩
Samrat
Posted on August 31, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.