What are objects?

JavaScript is a prototype based object oriented Programming language. so basically we work with objects of these prototypes. Let me put it in simpler terms that these objects are similar to real world object.

e.g. Book, so how can we recognize anything that it is book or not? Answer is by looking at the prototype of the book, like how does book look? what are the functionality? etc.

Book is an Object that contains various properties like title, author name, price and Numbers of pages etc.

So like as I earlier said JavaScript is a prototype based object oriented language that means each object is unique instance of an object prototype as each book is unique instance of idea of how book should look like.

As every object needs some place to live in real world so does our JS objects. We need some type of container to hold these JS objects.

What are Object Container?

As we know Object need place to live and its name to recognize here variables comes into the picture, Variable are used as container to hold that object and we should use constant variable to hold our object.

Example:

(Figure: 1)

As you can see in the figure 1, Book is a object container it holds an object of Science’s Book whose price is 120.

Can we use any other variable type to hold our object or why should we keep our object in constant variable?

Answer is Yes, we can. But holding object in var/let type variable come with drawback like if accidentally or for reason you change the value then object will get overwritten.

so to avoid such kind of problem we use constant variable. As we know constant value can’t be changed, it is safer place for an object to reside but still we can change the value of properties inside the object.

What are Object Properties?

Properties can be defined as colon separated key value pair.

Example:

(Figure: 2)

Where key name can be anything it is placed before the colon on the left side while value can be anything (string, number and so on). If it is string value then it will be inside the Quotation marks.

Here is the exercise for you, open the console of your favorite browser.

  1. Create an object like i have shown in the figure 1.
  2. Define some properties as title in the figure 2.
  3. Try to change the whole object with some value see what happens.

Tada! We did it. Great job 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *