DEV Community

Imran Shaik
Imran Shaik

Posted on

2

Explain Closure in detail ?

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');
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more