Mid From PDF JavaScript JavaScript

What are JavaScript closures and how are they used?

A closure is created when a function remembers variables from its outer scope, even

fter that outer function has finished executing.

Example:

function makeCounter() {

let count = 0;
return function() {
return ++count;

};

}
const counter = makeCounter();

console.log(counter()); // 1

console.log(counter()); // 2

✅ Use cases: data privacy, memoization, and function factories.

More from JavaScript Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details