- Back to Home »
- JavaScript »
- JavaScript Part-12 Closures
Posted by :
Sudhir Chekuri
Saturday, 10 March 2018
A closure in JavaScript is an inner function that has access to its outer function's scope, even after the outer function has returned control. A closure makes the variables of the inner function private. A
Simple example of a closure is shown below:
var count = (function () {
var _counter = 0;
return function () {return _counter += 1;}
})();
count();
count();
count();
// the counter is now 3
The variable count is assigned an outer function. The outer function runs only once, which sets the counter to zero and returns an inner function. The _counter variable can be accessed only by the inner function, which makes it behave like a private variable.
return function () {return _counter += 1;}
})();
count();
count();
count();
// the counter is now 3
The variable count is assigned an outer function. The outer function runs only once, which sets the counter to zero and returns an inner function. The _counter variable can be accessed only by the inner function, which makes it behave like a private variable.

I’m delighted to have found your webpage and look forward to enjoying more engaging content. I sincerely appreciate all the valuable information you’ve shared about SAP PP Production Planning. Thank you again for helping readers understand manufacturing and production processes in such a clear and practical way!
ReplyDeleteBest SAP PP Training in Chennai
Insightful write-up! I really appreciate how you emphasized the blend of academic learning and real-world application — it perfectly captures today’s evolving approach to skill development.
ReplyDeleteDeep Learning Course In Chennai
Data Science Training In Chennai
Machine Learning With Python Course In Chennai
Data Science With R Programming Training In Chennai
Data Science With Python Training In Chennai
Mean Stack Training In Chennai
Mern Stack Course In Chennai
Angular Training In Chennai
Wordpress Course In Chennai