Relative Content

Tag Archive for javascriptclosures

What are closures in JavaScript, and how do they work?

“What are closures in JavaScript? How do they function?
Closures allow inner functions to access outer function’s variables even after outer function execution.
Example: function outer() { let x = 10; return function inner() { console.log(x); } } const innerFunc = outer(); innerFunc(); // Output: 10”