DEV Community

Bhupesh Chandra Joshi
Bhupesh Chandra Joshi

Posted on

Understanding Object-Oriented Programming in JavaScript

How object oriented comes into piture, there are two developers who has been assigned one same project to built it, First developer scurry who is procedural and the second developer is haw who is object oriented programmer. JavaScript is more functional procedural
focused language, everything in JavaScript has objects. They have a adjustable chair like all Banglore techies have.

JavaScript objects are different from other programming languages and objects can formulated in two forms.

1- Literal form
let students={
name:"Vivek",
school:"Birla",
age:20,
gender:male,
likes:{
games:"football",
isMobile:true,
},
sayHello(){
console.log("Hello")

}
}
2- constructed form.
let company=new Object();
company.name="chaicode";
The only difference is , you can add the properties one by one to constucture formed object.

We have learnt that functions are first class objects in JavaScript, that closures make them extremely useful. Objects are prototypes in javaScript. function, prototypes and classes are objects in javascript ,where you can define properties.

You can consider class is a book and object is book's page, blueprint(class hoti hai) and → objects(instance of that class). As we have Witnessed the objects are unique set of properties ,or you can say that these are key value pair.

In JS, classes use prototype-based inheritance,if two objects inherit properties (generally function-valued properties, or methods)from the same prototype, then we say that those objects are instances of
the same class. That, in a nutshell, is how JavaScript classes work.

We have two ways to achieve enpsulation, one we achieve with help of closures and another one with help of class with private variables as we have created on the program, encapsulation is a injection,rapper and medicine are wraped arround, same as we wrap code and data into the single unit.

Top comments (0)