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