Dependency Injection in JavaScript
Passing a component's dependencies in from outside rather than having it construct or reach out for them internally, improving testability and flexibility.
Dependency injection (DI) is a design principle where a function, class, or module receives the other pieces of code it depends on (its 'dependencies') as explicit parameters or arguments, rather than constructing those dependencies internally or reaching out to fetch them directly (like importing a specific concrete module or instantiating a specific class by name deep inside its own logic). It's less a JavaScript-specific pattern than a general architectural principle, but it shows up constantly in JS backend frameworks and is a favorite senior-level interview topic for gauging architectural judgment around testability and coupling.
Dependency injection is like a restaurant kitchen that receives ingredients delivered by whichever supplier the manager has currently arranged, rather than each individual chef personally growing their own vegetables and raising their own livestock in the back alley — swapping to a different, better supplier (or a test 'fake' supplier for a recipe rehearsal) never requires retraining the chef's actual cooking technique, since the chef only ever depends on 'whatever ingredients get handed to me,' not any one specific supplier.