Promises Deep Dive

Before promises, we handled asynchronous code with callbacks which were hard to handle well. besides being an unreadable code (pyramid of doom), trying to handle multiple callbacks to run after an asynchronous operation ended or handle a completed process later in the code was hard to handle. There was a need for a better coding approach for handling asynchronous events.

Continue reading “Promises Deep Dive”

Composition Over Inheritance

Before we start to understand the limitations of inheritance and how you can solve them with composition it will be good to point out that prototypal inheritance is for object-oriented programming paradigms as closures are for functional programming paradigms and that inheritance is when you design your types around what they are while the composition is when you design your types around what they do.

Continue reading “Composition Over Inheritance”

JavaScript Factories

Sometimes the creation of an object can be complicated and the factory pattern can be used to simplify that and hide a lot of that from our front end. Basically, the factory pattern can help us simplify object creation and create different objects based on need. in this article, we will see simple examples to understand the factory pattern in JavaScript and the advantages over the others.

Continue reading “JavaScript Factories”

JavaScript – Object Oriented Programing

Object Oriented Programing means bringing together the data and the behavior in a single location called an object. data and behavior are the 2 main things in programs. data means the things we keep in memory and behavior means functions, the things that programs can do. This paradigm is entirely different than the functional programming paradigm that keeps a separation between the data and behavior.

Continue reading “JavaScript – Object Oriented Programing”

Asynchronous JavaScript

Javascript is single-threaded, only one statement is executed at a time. If something in our code is a long process it will freeze our application (block the thread) until it finishes. But as I explained in my previous articles, JavaScript does not work alone in the browser, we have the web API which is a set of features that help us run code asynchronously, a code that runs with callbacks in the background and does not freeze our application.

Continue reading “Asynchronous JavaScript”

JavaScript – Functional Programing

Functional programming is all about separation of concern which object-oriented programing does as well. but in functional programming, we don’t combine the data and functions in one piece or one object like with object-oriented programming. the functions operate on well-defined data structures like arrays and objects rather than belonging to the data structure like an object.

Continue reading “JavaScript – Functional Programing”