JavaScript under the hood
Today, I’ll like to take a quick peak at some of the more features that Javascript operates on. We’re going to take a look at what makes Javascript an Object Orientated Programming Language(OOP), how JS deals with classes, why use encapsulation and inheritance through a JS viewpoint.
First up, Objects are an entity in your code that has properties and actions. Example of an object is a Person is an object it has properties such like name and age and walking is an action a Person take. Almost everything in JS is an Object, learning how to work with objects will improve your productivity in JS.

Objects goes into the next topic, Classes. Classes are an object’s template like an object of teacher is an instance of the class person. Javascript is different because it doesn’t have real classes it has objects that inherit properties and actions from other objects. We could use this to start the discussion on inheritance but let’s take a look at encapsulation first.
Encapsulation is the process of wrapping an object’s properties and functions together, this hides an object’s internal parts to separate the description of an object with the implementation of the object. Gives the ability to use a “class” without needing to know how the methods are made. This brings us back to the inheritance topic. What if we only want some of the methods from another object to create another object.

Finally. Some properties and methods of an object are being used by another object is called inheritance. Objects inherit from one another in the other languages classes inherit from other classes which is called class inheritance. But, Javascript’s inheritance method is called prototype inheritance. all JS objects have a hidden property that is either null or it reference another object which is the prototype. When a child object is inheriting from a parent object JS wires the child prototype property (constructor) to the parent’s constructor method. This is an important topic because to be efficient developers we need to reuse code and inheritance is a fundamental mechanism for this. If shared code is wrong it could create a lot of problems.
Prototype inheritance solves a number of issues class inheritance causes in object orientated programming. Introducing the gorilla/ banana problem. All you wanted was the a specific property of banana but with class inheritance you get everything that goes along with the banana aka the gorilla.

These are the foundational pieces of Javascript. We will continue on the topic of JS in the next week’s blog post.
Thanks for reading.