XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
JavaScript Design Patterns
Review your understanding of common design patterns used in JS/TS.
1. Which design pattern ensures a class has only one instance and provides a global point of access to it?
Singleton
Factory
Observer
Module
2. Which pattern creates objects without specifying the exact class to instantiate?
Factory
Constructor
Prototype
Decorator
3. Which pattern encapsulates code by using closures to create private and public members?
Module
Observer
Adapter
Facade
4. Which pattern defines a one-to-many dependency between objects so that when one object changes state, all dependents are notified?
Observer
Strategy
Decorator
Singleton
5. Which pattern uses a constructor function with the 'new' keyword to initialize objects with shared properties?
Constructor
Prototype
Factory
Module
6. Which pattern leverages the prototype chain to share methods among instances, reducing memory usage?
Prototype
Decorator
Adapter
Facade
7. Which pattern dynamically adds or overrides behavior of an object at runtime without modifying its class?
Decorator
Observer
Strategy
Singleton
8. Which pattern enables selecting an algorithm's implementation at runtime by encapsulating each algorithm?
Strategy
Adapter
Facade
Module
9. Select all creational design patterns from the following:
Singleton
Factory
Observer
Prototype
Decorator
10. Which patterns promote loose coupling between components?
Observer
Mediator
Adapter
Singleton
Module
11. Which patterns are used to dynamically add functionality to objects?
Decorator
Mixin
Strategy
Adapter
Observer
12. Identify all structural design patterns:
Adapter
Decorator
Facade
Composite
Observer
13. Which patterns involve a 'subject' that notifies other objects of state changes?
Observer
Mediator
Pub/Sub
Singleton
Factory
14. The Singleton pattern is thread-safe by default in JavaScript.
True
False
15. The Module pattern typically uses IIFEs (Immediately Invoked Function Expressions) to create private scope.
True
False
16. JavaScript's inheritance model is based on the Prototype pattern.
True
False
17. The Observer pattern is identical to the Publish-Subscribe pattern.
True
False
18. What design pattern is characterized by objects (observers) registering to receive updates from a central object (subject)?
19. Name the structural pattern that provides a simplified interface to a complex subsystem (full name or common abbreviation).
20. What pattern uses closures to create private variables and expose public methods that can access them?
Reset
Answered 0 of 0 — 0 correct