function makeCounter() {
let n = 0
return () => ++n
}
const counter = makeCounter()
counter() // β 1
counter() // β 2The counter closure keeps its own private count variable, so each call increments independently without any global state.
A closure is a function that has access to variables from its outer scope even after the outer function has returned.
Challenge: Create a makeCounter function that returns a function. Each time the returned function is called, it should increment and return a counter starting from 1.
Example:
const counter = makeCounter()
counter() // 1
counter() // 2
counter() // 3