function bank() {
let balance = 500; // Private variable function deposit(amt) { balance = balance + amt; // Accessing outer scope variable return balance; } return deposit; }
const depositFn = bank();
What happens here?
The bank() function holds an internal variable balance.
The inner function deposit() updates and returns the balance.
Even after bank() finishes executing, depositFn remembers the balance variable!
