Toptal - Marko Misura Flashcards
JavaScript Design Patterns https://www.toptal.com/javascript/comprehensive-guide-javascript-design-patterns?utm_source=Code+with+Dan+Web+Development+Newsletter&utm_campaign=eae59a751e-The_Web_Weekly_Edition_23_COPY_01&utm_medium=email&utm_term=0_8ad074a071-eae59a751e-184823205
What are the benefits of design patterns?
- They are proven solutions (used by multiple developers and usually optimized) - They are easily reusable (can be modified to solve multiple particular problems, but not tied to a specific problem) - Expressive (can explain a large solution elegantly) - Ease communication (developers familiar with design patterns result in better communication about potential solutions) - Prevent the need for refactoring code (usually already an optimal solution) - Lower the size of the codebase (usually elegant and optimal solutions, smaller code)
Describe what JavaScript is.
JavaScript is a lightweight, interpreted, object-oriented programming language with first-class functions most commonly known as a scripting language for web pages. The aforementioned definition means to say that JavaScript code has a low memory footprint, is easy to implement, and easy to learn, with a syntax similar to popular languages such as C++ and Java. It is a scripting language, which means that its code is interpreted instead of compiled. It has support for procedural, object-oriented, and functional programming styles, which makes it very flexible for developers.
JavaScript supports first class functions, what does this mean?
JavaScript treats functions as first-class citizens, meaning you can pass functions as parameters to other functions just like you would any other variable.
JavaScript Is Prototype-based, what does this mean?
The language doesn’t support classes in its plain language form but rather uses something called prototype-based or instance-based inheritance. Prototype-based programming is a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects via delegations that serve as prototypes.
Describe the JS event loop.
Each time an event, which has a listener attached to it, fires (otherwise the event is lost), a message is being sent to a queue of messages which are being processed synchronously, in a FIFO manner (first-in-first-out). This is called the event loop.
Each of the messages on the queue has a function associated with it. Once a message is dequeued, the runtime executes the function completely before processing any other message. This is to say, if a function contains other function calls, they are all performed prior to processing a new message from the queue. This is called run-to-completion.
while (queue.waitForMessage()) { queue.processNextMessage(); }
The queue.waitForMessage() synchronously waits for new messages. Each of the messages being processed has its own stack and is processed until the stack is empty. Once it finishes, a new message is processed from the queue, if there is one.
What is meant by JS being non-blocking?
You might have also heard that JavaScript is non-blocking, meaning that when an asynchronous operation is being performed, the program is able to process other things, such as receiving user input, while waiting for the asynchronous operation to complete, not blocking the main execution thread. This is a very useful property of JavaScript.
What is a proto-pattern?
A proto-pattern is a pattern-to-be if it passes a certain period of testing by various developers and scenarios where the pattern proves to be useful and gives correct results. There is quite a large amount of work and documentation—most of which is outside the scope of this article—to be done in order to make a fully-fledged pattern recognized by the community.
What is an anti-pattern?
As a design pattern represents good practice, an anti-pattern represents bad practice.
An example of an anti-pattern would be modifying the Object class prototype.
What are the typical 5 design pattern categories?
Creational design patterns
Structural design patterns
Behavioral design patterns
Concurrency design patterns
Architectural design patterns
Name 5 popular creational design patterns.
These patterns deal with object creation mechanisms which optimize object creation compared to a basic approach. The basic form of object creation could result in design problems or in added complexity to the design. Creational design patterns solve this problem by somehow controlling object creation. Some of the popular design patterns in this category are:
Factory method
Abstract factory
Builder
Prototype
Singleton
Name 7 structural design patterns.
These patterns deal with object relationships. They ensure that if one part of a system changes, the entire system doesn’t need to change along with it. The most popular patterns in this category are:
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Name 9 Behavioral design patterns.
These types of patterns recognize, implement, and improve communication between disparate objects in a system. They help ensure that disparate parts of a system have synchronized information.
Chain of responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
Name 3 concurrency design patterns.
These types of design patterns deal with multi-threaded programming paradigms. Some of the popular ones are:
Active object
Nuclear reaction
Scheduler