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

1
Q

What are the benefits of design patterns?

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe what JavaScript is.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JavaScript supports first class functions, what does this mean?

A

JavaScript treats functions as first-class citizens, meaning you can pass functions as parameters to other functions just like you would any other variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JavaScript Is Prototype-based, what does this mean?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe the JS event loop.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is meant by JS being non-blocking?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a proto-pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an anti-pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the typical 5 design pattern categories?

A

Creational design patterns

Structural design patterns

Behavioral design patterns

Concurrency design patterns

Architectural design patterns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Name 5 popular creational design patterns.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name 7 structural design patterns.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Name 9 Behavioral design patterns.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name 3 concurrency design patterns.

A

These types of design patterns deal with multi-threaded programming paradigms. Some of the popular ones are:

Active object

Nuclear reaction

Scheduler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Name 3 popular architectural design patterns.

A

MVC (Model-View-Controller)

MVP (Model-View-Presenter)

MVVM (Model-View-ViewModel)