Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62
Subscribe to my email list now at http://jauyeung.net/subscribe/
To get a job as a front end developer, we need to nail the coding interview.
Functional programming concepts include pure functions, which are functions that avoid side effects, composing functions, and passing functions as arguments since functions are first class.
The immutability of objects are also important with functional programming to avoid bugs from multiple entities changing the same object.
Language with class inheritance has classes that are blueprints for creating objects.
We can also have subclasses that are children of a parent class. Therefore, there is a class hierarchy.
Instances of the class are created with the
Prototypical inheritance is where instances of an object directly inherit from a prototype object.
Instances are generally created from factory functions. Instances may be composed of many different objects.
new operator is used with constructor functions, which are factory functions that are used to create new instances of objects.
OOP is easy to understand and the basic concepts of objects are easy.
Therefore, it’s easy to interpret to the meaning of its members.
OOP uses an imperative style of programming rather than a declarative style. Imperative programming means that statements are used to change a program’s state.
Declarative programming describes logic without describing the control flow.
OOP depends on shared state. Objects and behaviors are put together into one entity. The members of the entity may be accessed in any more.
This may lead to issues like race conditions.
Functional programming uses pure functions to avoid any side effects. This eliminates bugs from multiple functions changing the same resource.
Functions tend to be simplified and composable for more reusable code compared to OOP.
Functional programming generally uses declarative styles, which do not write out everything step by step.
This means there’s more room for refactoring and we can replace algorithms with more efficient ones more easily.
Because of its declarative style, functional programming code is harder to read since not everything is written out line-by-line.
Functional programming also has more academic material than OOP materials since OOP has more materials targeted at beginners because of its popularity.
Classic inheritance is only appropriate for a single level of inheritance. Multiple levels of inheritance is always an antipattern.
Multiple levels are confusing and hard to read.
Object composition is better than inheritance.
Prototypical inheritance is useful since it allows for composition.
This means that objects can have the has-a, uses-a or can-do relationship, as opposed to the is-a relationship with class inheritance.
We can compose objects from multiple sources with prototypical inheritance and use mixins or
Object.assign to combine multiple objects into one.
Code should be assembled from smaller units of functionality into new objects instead of inheriting from classes and creating object taxonomies.
This means that instead of an is-a relationship, they can have a can-do, has-a, or uses-a relationships.
With composition, we avoid class hierarchies, tight coupling, and rigid taxonomy.
It also makes code more flexible.
Long-running networking requests and I/O operations will prevent the rest of the app from running.
Asynchronous programming means that the engine runs in an event loop. Blocking operations are queued in the event loop instead of running immediately. Therefore, the code won’t block the rest of the code from running.
When the response is ready, then the event handler runs and the control flow for the asynchronous code continues.
This way, a single program thread can handle many concurrent operations.
Objects are composed of inheriting from prototype objects instead of having a rigid class hierarchy. The class syntax doesn’t make that any different.
Objects are created from constructor functions.