Junior 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