dev-resources.site
for different kinds of informations.
Explain Closure in detail ?
Published at
12/23/2024
Categories
interview
javascript
react
angular
Author
Imran Shaik
A Closure is a feature in JavaScript where a function "remembers" the variable from its lexical Scope
(the scope in which it was created) even after the outer function has finished executing. This allows inner functions to access variables from their enclosing scope, even if the outer function is no longer active.
Example of Closure
function outerFunction(outerVariable){
return function innerFunction(innerVariable){
console.log(`outer variable : ${outerVariable}`);
console.log(`inner variable : ${innerVariable}`);
};}
const closureFunction = outerFunction('outside');
closureFunction('inside');
Articles
6 articles in total
Explain Closure in detail ?
currently reading
What is generator function in JavaScript? and How does it work?
read article
Reverse a string in JavaScript without using reverse()
read article
Different Ways to find maximum number in javascript
read article
How do we sort an Array in Javascript without Sort function?
read article
Different ways to create Objects in Javascipt
read article
Featured ones: