Objects and their internal representation in Javascript.

Mounisri
2 min readNov 17, 2020

Objects in javascript are the most important data types and forms building blocks for modern javascript. These objects are quite different from javascript primitive data types(Number, String, Boolean, null, undefined, and symbol) in the sense that while these primitive data-types all store a single value each (depending on their types).

Objects and variables:

Objects are variables too, but objects can contain many values. The values are written as name: value pairs (name and value separated by a colon).

eg: var data={name:”mouni”,age:21,id:1248}

Whereas javascript variables contain a single value.

eg: var name=”mouni”;

Creating Objects in Javascript :

There are 3 ways to create objects

1.By object literal.

2. By creating an instance of an object directly.

3.By using an object constructor

JavaScript Object by object literal

syntax:

object={property1:value1,property2:value2…..propertyN:valueN}

As you can see, property and value is separated by : (colon).

By creating an instance of Object

syntax:

  1. var objectname=new Object();

Here, new keyword is used to create object.

By using an Object constructor

Here, you need to create a function with arguments. Each argument value can be assigned in the current object by using this keyword.

The this keyword refers to the current object.

var person = {
firstName: “mouni”,
lastName : “sri”,
id : 776,
fullName : function() {
return this.firstName + “ “ + this.lastName;
}
};

JavaScript Object Methods:

There are some methods in javascript.

1.Object.assign(): This method is used to copy enumerable and own properties from a source object to a target object

2. Object.create(): This method is used to create a new object with the specified prototype object and properties.

3.Object.entries(): This method returns an array with arrays of the key, value pairs.

4.Object.keys(): This method returns an array of a given object’s own property names.

Thankyou.

--

--