Design Patterns · Junior · Question 3 of 75
What does the Singleton pattern guarantee?
- ✓Correct answer: A class has only one instance and a global access point to it
- 2Each constructor call creates a new independent instance
- 3The object can't be changed after creation, as with
Object.freeze
Explanation
Examples: one API client, one logger, one DB connection. In JS, the simplest singleton is a module: export const api = new ApiClient() - a module runs once, and all importers get the same object.