We introduced object oriented programming previously. This programming methodology, of course, is based on objects. But what are objects, exactly?

At some point during the global effort made by programmers to help themselves create better programs, faster, more efficiently and all, the idea came to introduce this concept of objects.

In object oriented programming, you define a set of classes, or types of objects.

An object is an instance of a class, and it contains both code and data. The data is abstracted away in to the object, and the object is responsible for providing methods (which are functions attached to an object) to manipulate this data.

Say you have a Dog class. You can create a myDog object by instantiating a new Dog:

const myDog = new Dog()

Roger is my dog’s name, so I can say so using

myDog.name = 'Roger'

A dog has an age:

myDog.age = 7

and we’ll have ways to retrieve this data.

The simplest way, in the case of JavaScript, is to just reference the property:

myDog.name //Roger

Here I defined public properties. In general, classes offer public and private properties. Private properties allow to encapsulate data, and only let it be accessed using methods that you define.

Now, we’ll talk a lot more about objects in the JavaScript Fundamentals course - in the meantime, I hope this little introduction served as an appetizer!


Go to the next lesson