Objects in JavaScript

Md Farhad Hossain
2 min readSep 20, 2020

What is an object?

In JavaScript object in an entity which contains properties and values. In other word object is a collection of properties, where every property is an association between a name (or key) and a value. A property’s value can be an integer, float, function(method) or object. In addition to the default objects in the browser, you can define your own objects.

Some browser predefined objects in JavaScript:

  1. Window Object
  2. History Object
  3. Screen Object
  4. Navigator Object
  5. Location Object
  6. Popup Boxes

Object Overview:

Object in JavaScript or in other programming languages can be compared in real life objects. The concept of object can be understand if we see an example from real life.

In JavaScript an object in a unique entity with properties an type. If we compare it with a chair. It has legs , color, weight, height and materiel it is made of it can be iron or wood.

Most likely in JavaScript, if you think about a person as an object then he has a name, age, height, weight, designation pointing object property.

Now we see in code.

Object declaration in JavaScript

Accessing an object

objectName.propertyName or objectName[“propertyName”]

Like person.name or person[“name”]

Object method

You can also define a method in an object as a property.

Object method

You can also access the object method using dot notation like this -

person.fullName();

Do you notice that? here we use this keyword in fullName method.What is that what does it means.🤔

It means when we use this keyword in an object method it refers the object own property. In here this.firstName means the firstName property of this object.

Object destructuring JavaScript

The destructuring syntax is a JavaScript expression that makes it possible to unpack values from objects, into distinct variables. You can easily unpack object properties using destructuring syntax. Let’s see an example.

object destructuring

To destructure an object make sure you have written the property name that you used inside the object. By convention you have to write the same name otherwise it will show you an error.

--

--

Md Farhad Hossain
Md Farhad Hossain

Written by Md Farhad Hossain

0 Followers

Technology enthusiast, diligent and has a great ability to learn something new quickly. Obviously a good human being and affable.

No responses yet