Design patterns are not code snippets that can be used directly in your code (like a data structure). Rather, they’re a recipe for how to solve a problem in software engineering. Design patterns are structured best practices that the programmer can use to solve common problems when developing (or designing) an application or system.

It is important for developers to be able to recognize and apply these patterns correctly to avoid reinventing the wheel. I will detail some commonly used design patterns in JavaScript to show it is possible to use design patterns in the JavaScript world.

Creational Patterns

Prototype

This is a design pattern used specifically to clone attributes of an object into new objects, hence the word prototype. JavaScript does this by creating new objects, so setting up your own prototype is an important design pattern to know, especially in JavaScript.

Module

The module pattern is probably the most commonly used pattern after prototype. Modules should be Immediately-Invoked-Function-Expressions (IIFE). All of the module code exists within a closure. Import variables by passing in values through the function execution.
Export variables (expose variables) by returning an object.

Why use a module? A module should be used in any system beyond a single function JavaScript. It’s helpful not to pollute the global namespace and keep your functions importable and exportable.

Behavioral Patterns

Observer

If you are writing JavaScript to do anything fancy, you are probably already using the observer pattern. When you create an event handler, such that functions are executed when the event has been fired, that’s the observer pattern. An observer pattern, is a subscription model, where you assign your object to listen to events.

Cleaner, Clearer Code

Developers can apply design pattern thinking to write cleaner, more organized JavaScript. The growing use and popularity of frameworks that use design patterns—Ember, React, KnockoutJS—make it a necessity be able to identify and utilize software design patterns more than ever. I encourage developers to use as many design patterns in JavaScript as possible. This comprehensive list of exceptionally well thought out design patterns examples in JavaScript is a great resource to continue the path of discovery.