Junior From PDF JavaScript JavaScript

What is a closure?

A closure is when a function remembers variables from its outer scope even after the

outer function has finished executing.

Example:

function counter() {

let count = 0;
return function() {

count++;

return count;

};

}
const add = counter();

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

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