Private Variables
Closures enable data privacy by creating variables that cannot be accessed directly from outside. Only the returned functions can access and modify them.
function createPerson(name) { let _name = name; // private return { getName() { return _name; }, setName(newName) { _name = newName; }, };}const person = createPerson("Alice");console.log(person.getName()); // Aliceperson.setName("Bob");console.log(person.getName()); // Bob