Objects and Its Internal Representation

gokul giri
2 min readNov 9, 2020

Objects in Javascript is a important data type.They are mutable. They comes under the non primitive data types. Objects are more complex and may contain any combination of these primitive data-types as well as reference data types.

Object is a reference data type. Variables that are assigned a reference value are given a reference or a pointer to that value. Reference or pointer points to the location in memory when the object is stored.

Values of the type object are arbitrary collections of properties.

Objects are unordered collection of related data of primitive or reference types is the form of the “key : value” pairs. Objects can be created with figure brackets{…}. One way to create an object is by using braces as an expression.

let day1 = {squirrel: false,events: [“work”, “touched tree”, “pizza”, “running”]};

console.log(day1.squirrel);

// → false

console.log(day1.wolf);

// → undefined

day1.wolf = false;

console.log(day1.wolf);// → false

Inside the braces, there is a list of properties separated by commas. Eachproperty has a name followed by a colon and a value. When an object is writtenover multiple lines, indenting it like in the example helps with readability.Properties whose names aren’t valid binding names or valid numbers have tobe quoted.

let descriptions = {

work: “Went to work”,

”touched tree”: “Touched a tree”

};

This means that braces have two meanings in JavaScript. At the start of a statement, they start a block of statements. In any other position, they describe an object. Fortunately, it is rarely useful to start a statement with an object in braces, so the ambiguity between these two is not much of a problem. Reading a property that doesn’t exist will give you the value undefined. It is possible to assign a value to a property expression with the “=” operator.

Property bindings are similar. They grasp values, but other bindings and properties might be holding onto those same values. You may think of objects as octopuses with any number of tentacles, each of which has a name tattooed on it.The delete operator cuts off a tentacle from such an octopus. It is a unary operator that, when applied to an object property, will remove the named property from the object. This is not a common thing to do, but it is possible

let anObject = {left: 1, right: 2};

console.log(anObject.left);

// → 1

delete anObject.left;

console.log(anObject.left);

// → undefined

The binary in operator, when applied tells us whether that Object has a property with that name.

console.log(“left” in anObject);

// → false

console.log(“right” in anObject);

// → true

There’s an Object.assign function that copies all properties from one object into another.

let objectA = {a: 1, b: 2};

Object.assign(objectA, {b: 3, c: 4});

console.log(objectA);

// → {a: 1, b: 3, c: 4}

To access the parameter inside the Objects, we can use Bracket keywords. they are better than (.) operators.

let data =[{"name":"Afghanistan","topLevelDomain":[".af"],"alpha2Code":"AF","alpha3Code":"AFG","callingCodes":["93"]
},{"name":"Austria","topLevelDomain":[".at"],"alpha2Code":"AT","alpha3Code":"AUT","callingCodes":["43"],"capital":"Vienna"}];
// to find the capital of austria
data[1]['capital] ===>> "vienna"

--

--