DEV Community

Vivekanandhan-Elavarasan
Vivekanandhan-Elavarasan

Posted on

JavaScript Objects - Internal Representation

An object in JavaScript is like a class in object-orientated languages.
Objects represent things, like cars for example.
The object is the car.Cars can have properties like color, the amount of cylinders in the vehicle, whether it’s automatic or manual, etc.
Cars can also accelerate, brake, etc. Generally we can represent this functionality as a ‘method’ of the object. Objects also have properties known as ‘prototypes’.
datatypes are classified as Primitives and Composites. Primitives are the string, Boolean and number.

{} // this is an empty object
var myObj = {a: 1, b: 2} // myObj is assigned an object
// this object has 2 keys (a and b) and 2 values (1 and 2)

// we can get a value from an object by referencing the key

myObj['a'] // this is called bracket notation and returns 1
myObj.b // this is called dot notation and returns 2 here

Any valid JavaScript value may be associated with a key in a JavaScript object. A value attached to an object is referred to as a “property”. A property that is a function is referred to as a “method”.

Object constructor: In JavaScript, there is a special constructor function known as Object() is used to create and initialize an object. The return value of the Object() constructor is assigned to a variable. The variable contains a reference to the new object. We need an object constructor to create an object “type” that can be used multiple times without redefining the object every time.

function GFG(A, B, C) {
this.g = A;
this.f = B;
this.gg = C;
}

object.property // person.height
object["property"] // person["height"]
object[expression] // x = "height"; person[x]

Java accept the numerical indexes and It can be represented as the key and values and this can be used as a constructor. We can represent in array of values in a object
var a={}
var b={[],[]}
we can represent and evaluate the values in particular if we use objects
If It is an array of objects.It has lenght of an array and we can increase the value of array of objects.

and Index of an array starts with 0 and empty value is undefined

In array of objects there are empty slots if we index above the predefined length of an array

var objname =new Object();

with help of new keyword we can create an array and represent an array

In this same way we can represent json object too
In this way we can represent an object in different ways as constructor, arrays, object.

Top comments (0)