FlashcardNot attempted
Singletons in JavaScript
Recall it before you reveal
How do you make a singleton in modern JS, and what is wrong with singletons?
Space to reveal
Show answer & explanation
Simplest: an ES module that exports an instance. Modules are evaluated once and cached, so every importer gets the same object (export const store = createStore()). A class with a static getInstance() adds lazy creation.
Downsides: hidden global state, tight coupling, and order-dependent tests (state leaks between tests). Prefer passing dependencies in (dependency injection) and keep singletons for truly app-wide services (a logger, a config, an API client).