Comprehensive glossary of key terms related to JavaScript and TypeScript design patterns, programming paradigms, and language features.
Welcome to the Glossary of Terms for “Modern Design Patterns in JavaScript and TypeScript.” This appendix serves as a comprehensive reference for key terms and concepts discussed throughout the book. Organized alphabetically, it provides clear definitions, practical examples, and contextual insights to enhance your understanding of design patterns, programming paradigms, and language-specific features. Whether you’re a seasoned developer or new to these concepts, this glossary aims to be an accessible and invaluable resource.
Abstraction
A fundamental principle in object-oriented programming that involves hiding the complex reality while exposing only the necessary parts. Abstraction helps in reducing programming complexity and effort by providing a simplified model of a complex system.
Adapter Pattern
A structural design pattern that allows incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces, making it easier to integrate new components without altering existing code.
Example:
class OldSystem {
request() {
return "Old system request";
}
}
class NewSystem {
specificRequest() {
return "New system request";
}
}
class Adapter {
constructor() {
this.newSystem = new NewSystem();
}
request() {
return this.newSystem.specificRequest();
}
}
// Usage
const adapter = new Adapter();
console.log(adapter.request()); // Output: "New system request"
Agile Development
A methodology for software development that emphasizes iterative development, collaboration, and flexibility. Agile promotes adaptive planning and encourages rapid and flexible responses to change.
API (Application Programming Interface)
A set of rules and protocols for building and interacting with software applications. APIs allow different software programs to communicate with each other, enabling integration and functionality sharing.
Asynchronous Programming
A programming paradigm that allows for non-blocking operations, enabling the execution of other tasks while waiting for an operation to complete. Commonly used in JavaScript for handling I/O operations without freezing the main execution thread.
Example:
async function fetchData() {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
console.log(data);
}
Behavioral Design Patterns
Design patterns that focus on communication between objects, how they interact, and how responsibilities are distributed among them. Examples include the Observer, Strategy, and Command patterns.
Builder Pattern
A creational design pattern that provides a way to construct complex objects step by step. It allows for more control over the construction process, often used when an object needs to be created with many configuration options.
Example:
class House {
constructor() {
this.doors = 0;
this.windows = 0;
this.roof = '';
}
}
class HouseBuilder {
constructor() {
this.house = new House();
}
addDoors(number) {
this.house.doors = number;
return this;
}
addWindows(number) {
this.house.windows = number;
return this;
}
setRoof(type) {
this.house.roof = type;
return this;
}
build() {
return this.house;
}
}
// Usage
const house = new HouseBuilder().addDoors(2).addWindows(4).setRoof('gabled').build();
Blockchain
A decentralized digital ledger that records transactions across many computers. It is the underlying technology for cryptocurrencies and enables secure, transparent, and tamper-proof record-keeping.
Callback Function
A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. Callbacks are used extensively in JavaScript for asynchronous operations.
Class
A blueprint for creating objects in object-oriented programming. Classes encapsulate data for the object and methods to manipulate that data. In JavaScript, classes are syntactical sugar over the existing prototype-based inheritance.
Closure
A feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables. Closures are used to create private variables or functions.
Example:
function outerFunction(outerVariable) {
return function innerFunction(innerVariable) {
console.log('Outer Variable: ' + outerVariable);
console.log('Inner Variable: ' + innerVariable);
};
}
const newFunction = outerFunction('outside');
newFunction('inside');
Command Pattern
A behavioral design pattern that turns a request into a stand-alone object containing all information about the request. This pattern allows for parameterizing methods with different requests, queuing requests, and logging the history of requests.
Concurrency
The ability of a program to execute multiple tasks simultaneously. In JavaScript, concurrency is achieved through the event loop and asynchronous programming techniques like Promises and async/await.
Decorator Pattern
A structural design pattern that allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.
Example:
class Coffee {
cost() {
return 5;
}
}
class MilkDecorator {
constructor(coffee) {
this.coffee = coffee;
}
cost() {
return this.coffee.cost() + 1;
}
}
const myCoffee = new MilkDecorator(new Coffee());
console.log(myCoffee.cost()); // Output: 6
Dependency Injection
A design pattern used to implement IoC (Inversion of Control), where a class receives its dependencies from external sources rather than creating them itself. This pattern is used to increase modularity and testability.
Duck Typing
A concept in dynamic programming languages where the type or class of an object is determined by its behavior (methods and properties) rather than its explicit declaration.
ECMAScript
The standardized scripting language specification upon which JavaScript is based. ECMAScript versions (e.g., ES5, ES6) introduce new language features and improvements.
Encapsulation
A principle of object-oriented programming that restricts access to certain components of an object and only exposes a limited interface. Encapsulation helps in protecting the internal state of an object from unintended interference.
Event Loop
A programming construct that waits for and dispatches events or messages in a program. In JavaScript, the event loop allows for asynchronous operations by handling the execution of code, collecting and processing events, and executing queued sub-tasks.
Facade Pattern
A structural design pattern that provides a simplified interface to a complex subsystem. It hides the complexities of the system and provides a client with an easier way to interact with it.
Factory Pattern
A creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created. This pattern promotes loose coupling by eliminating the need to bind application-specific classes into the code.
Functional Programming
A programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. Functional programming emphasizes the use of pure functions, immutability, and higher-order functions.
Generator Function
A special type of function in JavaScript that can pause its execution and resume later, allowing it to produce a sequence of results over time. Generators are defined using the function*
syntax and use the yield
keyword to produce values.
Example:
function* generatorFunction() {
yield 1;
yield 2;
yield 3;
}
const generator = generatorFunction();
console.log(generator.next().value); // Output: 1
console.log(generator.next().value); // Output: 2
GraphQL
A query language for APIs and a runtime for executing those queries by using a type system you define for your data. GraphQL provides a more efficient, powerful, and flexible alternative to REST.
Higher-Order Function
A function that takes one or more functions as arguments or returns a function as its result. Higher-order functions are a key feature of functional programming, allowing for greater abstraction and code reuse.
Hoisting
A JavaScript mechanism where variables and function declarations are moved to the top of their containing scope during the compile phase. This means that functions and variables can be used before they are declared.
Immutability
An object or data structure is considered immutable if its state cannot be modified after it is created. Immutability is a core concept in functional programming, promoting safer and more predictable code.
Inheritance
A mechanism in object-oriented programming where a new class is created from an existing class. The new class, known as the subclass, inherits properties and behaviors from the existing class, known as the superclass.
Interface
In TypeScript, an interface is a syntactical contract that an entity should conform to. It defines the structure that any implementing class must follow, ensuring consistency across implementations.
Iterator Pattern
A behavioral design pattern that provides a way to access the elements of a collection sequentially without exposing its underlying representation. Iterators are used to traverse collections like arrays and objects.
JavaScript
A high-level, dynamic, untyped, and interpreted programming language. It is one of the core technologies of the World Wide Web, alongside HTML and CSS, and enables interactive web pages.
JSON (JavaScript Object Notation)
A lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. JSON is a common format for transmitting data in web applications.
Key-Value Pair
A fundamental data representation in programming where each key is associated with a value. Key-value pairs are commonly used in objects, maps, and dictionaries.
Kubernetes
An open-source container orchestration system for automating application deployment, scaling, and management. Kubernetes is widely used for managing microservices and distributed applications.
Lazy Evaluation
A programming technique where expressions are not evaluated until their values are needed. Lazy evaluation can improve performance by avoiding unnecessary calculations.
Linter
A tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. Linters help maintain code quality and consistency.
Microservices
An architectural style that structures an application as a collection of loosely coupled services. Each service is self-contained and implements a specific business capability.
Middleware
Software that provides common services and capabilities to applications outside of what’s offered by the operating system. In web development, middleware functions are used to handle requests and responses in a server.
Mixin
A class containing methods that can be used by other classes without being a parent class. Mixins provide a way to share functionality between classes in a flexible manner.
Node.js
An open-source, cross-platform JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js is used for building scalable network applications.
Normalization
The process of organizing data in a database to reduce redundancy and improve data integrity. Normalization involves dividing a database into tables and defining relationships between them.
Observer Pattern
A behavioral design pattern where an object, known as the subject, maintains a list of its dependents, called observers, and notifies them of any state changes. This pattern is commonly used in event-driven programming.
Open/Closed Principle
A software design principle that states that software entities should be open for extension but closed for modification. This principle encourages the use of interfaces and abstract classes to allow the behavior of a module to be extended without modifying its source code.
Polymorphism
A feature of object-oriented programming that allows objects of different types to be treated as objects of a common super type. Polymorphism enables a single interface to represent different underlying forms (data types).
Promise
An object representing the eventual completion or failure of an asynchronous operation and its resulting value. Promises provide a cleaner alternative to callbacks for handling asynchronous operations in JavaScript.
Prototype
An object from which other objects inherit properties. In JavaScript, every object has a prototype, which is a reference to another object from which it inherits properties and methods.
Proxy Pattern
A structural design pattern that provides an object representing another object. A proxy controls access to the original object, allowing for additional functionality such as lazy initialization, logging, or access control.
Query Language
A language used to make queries in databases and information systems. SQL (Structured Query Language) is the most common query language used for managing relational databases.
Queue
A collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end. Queues follow the FIFO (First In, First Out) principle.
Reactive Programming
A programming paradigm oriented around data flows and the propagation of change. Reactive programming is used to build responsive and resilient systems.
Recursion
A method of solving a problem where the solution involves solving smaller instances of the same problem. Recursive functions call themselves with modified arguments to achieve this.
Redux
A predictable state container for JavaScript apps, often used with React for managing application state. Redux follows a unidirectional data flow architecture.
Singleton Pattern
A creational design pattern that restricts the instantiation of a class to one single instance. This pattern ensures that a class has only one instance and provides a global point of access to it.
Example:
class Singleton {
constructor() {
if (!Singleton.instance) {
Singleton.instance = this;
}
return Singleton.instance;
}
}
const instance1 = new Singleton();
const instance2 = new Singleton();
console.log(instance1 === instance2); // Output: true
SOLID Principles
A set of five design principles intended to make software designs more understandable, flexible, and maintainable. The principles are: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
State Management
The process of managing the state of an application, which includes data, UI state, and other relevant information. State management is crucial in building complex applications with dynamic interactions.
Strategy Pattern
A behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. The strategy pattern lets the algorithm vary independently from clients that use it.
TypeScript
A typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional static typing to the language, enabling developers to catch errors early and improve code quality.
Template Literal
A feature in JavaScript that allows for multi-line strings and string interpolation. Template literals are enclosed by backticks () and can contain placeholders indicated by the
${expression}` syntax.
Example:
const name = "World";
console.log(`Hello, ${name}!`); // Output: "Hello, World!"
Thread
A sequence of instructions that can be managed independently by a scheduler. In the context of JavaScript, the event loop allows for non-blocking execution without traditional threads.
UML (Unified Modeling Language)
A standardized modeling language used to specify, visualize, and document models of software systems. UML is used to describe the structure and behavior of a system.
Unit Testing
A software testing method where individual units or components of a software are tested. Unit testing ensures that each part of the code works as expected.
Variable Scope
The context within which a variable is defined and accessible. JavaScript has function scope and block scope (introduced with let
and const
in ES6).
Version Control
A system that records changes to a file or set of files over time so that you can recall specific versions later. Git is a popular version control system used in software development.
WebAssembly
A binary instruction format for a stack-based virtual machine. WebAssembly is designed as a portable compilation target for programming languages, enabling high-performance applications on web pages.
WebSocket
A protocol providing full-duplex communication channels over a single TCP connection. WebSockets are used for real-time web applications, allowing for bidirectional communication between a client and server.
XML (Extensible Markup Language)
A markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. XML is used for data interchange between systems.
XSS (Cross-Site Scripting)
A security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. XSS can be prevented by validating and sanitizing user inputs.
Yield
A keyword used in generator functions to pause execution and return a value. The function can be resumed later from where it was paused, allowing for the generation of a sequence of values over time.
YAML (YAML Ain’t Markup Language)
A human-readable data serialization standard that is commonly used for configuration files and data exchange between languages with different data structures.
Zero-Day Vulnerability
A software security flaw that is unknown to the software vendor and is exploited by attackers before a fix is released. Zero-day vulnerabilities can lead to significant security breaches.
Zigzag Iterator
An iterator that returns elements from multiple lists in a zigzag manner. This is a specific use case of the iterator pattern where traversal is done in an alternating sequence.
This glossary is designed to serve as a quick reference and learning aid. As you explore the book, refer back to this glossary to deepen your understanding of key terms and concepts. The definitions and examples provided aim to clarify complex ideas and demonstrate their practical relevance in software development. Whether you’re revisiting familiar terms or encountering new ones, this glossary will support your journey through the world of modern design patterns in JavaScript and TypeScript.