What is objects in javascript? How are they represented?

Seeli
2 min readNov 13, 2020

Objects

Objects in javascript indicates a group of unordered collection of data that belong to some common entity. An object can have datatypes such as number, string, array or even collection of objects or nested objects as a property or element.

Javascript follows an object oriented structure unlike other programming languages such as java which follows class hierarchy. To see in detail let us see its representation or definition. We have JSON — Javascript Object Notation which has data storage and access hierarchy in form of objects.

Initialization

There are three ways to represent objects, they are

1) By using literals-Let obj={‘a1’:12,’b1’:23};

2) By constructor- Let data=new Object();

3) By using method-Object.create(ring);

Key:value –

An object always takes a key and a value as its property. We can acess the values of the object only by using their keys.

Eg ‘name’:’Ravi kumar’

Keys should be always a string or a decimal it cant have direct numeric entries as keys.

Value should be entered after key separated by : (colon).

Object literals-

Object literals is to represent the object in comma separated values inside the curly braces.

By constructor-

We can have a function with attributes starting with ‘this’ by which we have keys and we can create the objects with values by simply passing the values to the constructor function.

By using object.create method-

Object.create(all) would result in creating an object named all. We now could see how we are going add key:value pairs ,modify them, add new objects or properties in detail.

Accessing objects-

We could use dot operator or use square brackets to call an objects properties.

Eg data.name;

Data[name];

Data.age=50, by which we could add new property to existing object .

We can also obtain all the keys of an object by using Object.Keys(data);

We can get all values by Object.Values(data)

Here data is the object that need to be accessed.

--

--