# Closures at Work: Private State and Factories

Put closures to work to keep a count that no other code can change, to build as many independent counters as you need with a factory function, and to make a function that runs only once.

![Cheat sheet: Closures at Work: Private State and Factories](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/10/6cc33ccc6a9c44f9b05d71c677e87d9a.webp)

- Category: JavaScript
- Level: Journeyman
- Tags: Closure (javascript), Encapsulation (javascript), Factory Function (javascript), JavaScript, State (oop)
- Updated: November 1, 2026

Source: https://www.ask-codey.com/cheat-sheets/javascript-closures-private-state-and-factories-cheat-sheet
