DEV Community

Cover image for JS/TS OOP: 2-Classes And Objects
Hasan Zohdy
Hasan Zohdy

Posted on

JS/TS OOP: 2-Classes And Objects


So we're going to start with the most important topic in OOP, which is Classes and Objects.

What is a class?

A class is a blueprint for creating objects, it defines a set of attributes that will characterize any object of the class. The attributes are called fields, and the functions are called methods.

This is the academic definition, but let's see our own definition.

Imagine a class like a definition of type, for example a human class defines the characteristics of human and his/her actions.

For example the human skin color is a characteristic, and the human walks, talks, eats, sleeps, etc. are actions.

So a class is a definition of a type, it defines the characteristics and the actions of the type.

In that sense we can say that a class is a blueprint or schema for things in life.

You can think of a class as a template or a descriptive book about a entity, how it shapes and how it acts and interacts with other types.

What is an object?

We now know that classes are the definition of a type, so what is an object?

An object is the real thing of that blueprint, for example me and you are objects of the Human class.

Your cat at your home is an object of the Cat class.

So an object is the real implementation or the actual object/item of a class.

Other terms for objects

You might read in an article, book or while watching a video the term object, also it is called instance of a class.

🎨 Conclusion

Classes are the blueprints of things, they are used to create objects, and objects are the real things of that blueprint.

In our next article, we'll learn about the structure of a class.

β˜•β™¨οΈ Buy me a Coffee β™¨οΈβ˜•

If you enjoy my articles and see it useful to you, you may buy me a coffee, it will help me to keep going and keep creating more content.

😍 Join our community

Join our community on Discord to get help and support (Node Js 2023 Channel).

πŸ“š Bonus Content πŸ“š

You may have a look at these articles, it will definitely boost your knowledge and productivity.

General Topics

Packages & Libraries

React Js Packages

Courses (Articles)

Top comments (1)

parsyvalentin profile image
Valentin PARSY

If you keep treating JS like an OOP language and thinking, for example, that a class is a blueprint, you are gonna end up with errors in your code.
In a JS a class is more than a blueprint because if you change it, you change every objects created with it