The two pillars of JavaScript.

JavaScript is a scripting or programming language that allows you to implement complex features on web pages. JavaScript used both on the client-side and server-side, allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user.

JavaScript is mainly used for web-based applications and web browsers. But JavaScript is also used beyond the Web in software, servers and embedded hardware controls, Adding interactive behavior to web pages, Creating web and mobile apps, Building web servers and developing server applications, Game development.

As one of the most important programming languages javaScript popularized two paradigms which are extremely important for the evolution of programming:

  • Prototypal Inheritance
  • Functional Programming

What is functional programming?

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data. Some Examples of functional languages: Lisp, ML, Haskell, Erlang, Clojure, Elm, F Sharp, OCaml, etc…

What is Prototypal Inheritance?

Prototypal Inheritance is when instances inherit directly from other objects. Instances are typically instantiated via factory functions or `Object.create()`. Instances may be composed from many different objects, allowing for easy selective inheritance. In JavaScript, prototypal inheritance is simpler & more flexible than class inheritance in which Instances are typically instantiated via constructor functions with the `new` keyword.

In JavaScript, objects have a special hidden property [[Prototype]] (as named in the specification), that is either null or references another object. That object is called “a prototype”:

There is more than one type of prototypal inheritance:

· Delegation (i.e., the prototype chain).

· Concatenative (i.e. mixins, `Object.assign()`).

· Functional (Not to be confused with functional programming. A function used to create a closure for private state/encapsulation).

Functional programming vs Prototypal Inheritance (object-oriented programming)?

— Objects and methods are very readable and understandable.

— OOP utilizes an imperative style, in which code reads like a straight-forward set of instructions as a computer would read it

· OOP Cons:

— OOP commonly depends upon shareable state. Objects and behaviors are typically tacked together on the same entity.The unfortunate result of so many objects and methods existing within the same state and being accessed in an entirely undetermined order can lead the pre-discussed concept of “race conditions”.

FP Pros:

— Utilizing pure functions, leads to reliable functions with no side effects that accomplish and return exactly what you expect them to.

— Using the functional paradigm, programmers avoid any shared state, which eliminates bugs caused by multiple functions competing for the same resources.

— FP utilizes a more declarative style, which focuses more on what to do and less about how it’s being done. This places the emphasis on performance and optimization, leaving the door to refactor without completely reworking your code.

FP Cons:

— Functional programming is a newer paradigm. More people are familiar with OO and imperative programming than functional programming, so even common idioms in functional programming can be confusing to new team members.

— Similar to one of OOP’s strengths, functional programming can lack readability at times. FP concepts are frequently written about using idioms and notations from lambda calculus, algebras, and category theory, all of which requires a prior knowledge foundation in those domains to be understood.

Sources: Eric Elliot —