← All topics

Design Patterns Junior interview questions and answers

75 questions for a Design Patterns (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What is a design pattern?
  2. 2.Into which three groups are the classic GoF patterns divided?
  3. 3.What does the Singleton pattern guarantee?
  4. 4.Why is Singleton often called an anti-pattern?
  5. 5.What problem does the Factory pattern solve?
  6. 6.How does the Observer pattern work?
  7. 7.How does Pub/Sub differ from the classic Observer?
  8. 8.What is the Strategy pattern?
  9. 9.What does the Decorator pattern do?
  10. 10.When do you need an Adapter?
  11. 11.What is a Facade?
  12. 12.What is the Proxy pattern used for?
  13. 13.Which pattern do for...of and Symbol.iterator implement?
  14. 14.What is the Module pattern in JavaScript?
  15. 15.When is the Builder pattern useful?
  16. 16.How is the Prototype pattern related to JavaScript?
  17. 17.What is the Command pattern used for?
  18. 18.Which pattern lets you treat a tree (a menu with submenus, a file system) uniformly?
  19. 19.What does the State pattern describe?
  20. 20.What does a Mediator do?
  21. 21.Which pattern underlies middleware in Express or Redux?
  22. 22.What is the Template Method pattern?
  23. 23.What is a Memento for?
  24. 24.Why do you need the Flyweight pattern?
  25. 25.What does the acronym SOLID stand for?
  26. 26.What does the Single Responsibility Principle (SRP) require?
  27. 27.What does the Open/Closed Principle (OCP) mean?
  28. 28.What does the Liskov Substitution Principle (LSP) require?
  29. 29.What is the Interface Segregation Principle (ISP) about?
  30. 30.What does the Dependency Inversion Principle (DIP) mean?
  31. 31.What does the DRY principle mean?
  32. 32.What does the KISS principle mean?
  33. 33.What does the YAGNI principle mean?
  34. 34.What does "composition over inheritance" mean?
  35. 35.What does the MVC pattern describe?
  36. 36.What is the Container/Presentational pattern in React about?
  37. 37.What pattern does a custom hook useWindowSize() implement?
  38. 38.Which pattern do React Context and <Provider> implement?
  39. 39.What is an anti-pattern?
  40. 40.What is a God Object?
  41. 41.What's wrong with "magic numbers" like if (status === 3)?
  42. 42.What is callback hell, and how is it avoided?
  43. 43.A function takes 7 arguments. Which refactoring is usually appropriate?
  44. 44.What is refactoring?
  45. 45.What is Separation of Concerns?
  46. 46.What does "high cohesion and low coupling" mean?
  47. 47.What is Dependency Injection in its simplest form?
  48. 48.Which pattern does EventEmitter in Node.js or EventTarget in the browser implement?
  49. 49.Why are pure functions useful in design?
  50. 50.Which pattern does a HOC like withLogger(Component) use?
  51. 51.What is the render props pattern?
  52. 52.What are compound components?
  53. 53.How does a controlled input differ from an uncontrolled one?
  54. 54.What does replacing nested ifs with guard clauses give you?
  55. 55.How can a long switch that maps a status to a label be simplified?
  56. 56.What is the Extract Function (Extract Method) refactoring?
  57. 57.What does the Bridge pattern separate?
  58. 58.Why is a very long function considered a code smell?
  59. 59.What should you do with dead code (unused functions, unreachable branches)?
  60. 60.Which comments are most valuable?
  61. 61.Which name is best for a boolean variable?
  62. 62.Why prefer creating new objects over mutating existing ones in UI state?
  63. 63.What is encapsulation?
  64. 64.What is polymorphism?
  65. 65.What's the difference between "is-a" and "has-a" relationships?
  66. 66.How do debounce and throttle differ?
  67. 67.What is an optimistic UI update?
  68. 68.What is lazy loading?
  69. 69.What are feature flags (feature toggles)?
  70. 70.What's the purpose of a fallback UI (e.g. a React error boundary)?
  71. 71.What does it mean that an operation is idempotent?
  72. 72.What does "single source of truth" mean for app data?
  73. 73.What is a config-driven (data-driven) UI?
  74. 74.What does the Principle of Least Astonishment say?
  75. 75.What does "premature optimization is the root of all evil" warn against?