Objects and its Internal Representation in JavaScript.

Radha Priyadarshan
2 min readFeb 18, 2024

--

let’s dive into the awesome world of JavaScript objects. We’re not just going to talk about their surface; we’re going to peek into the secret stuff that makes them work — without the confusing tech talk. Let’s make JavaScript objects as simple as making a sandwich!

Objects:

Object is a a super helper that can carry a bunch of different things for you. It can hold information like names, numbers, or even more objects. Think of it as a toolbox for your code. Objects are variables. Objects can contain many values. Object values are written as name : value pairs (name and value separated by a colon). Objects are similar to the dictionaries in python,Hash tables in C,Hash maps in Java.

Inside the Object:

When we create an object, we fill it with treasures called properties. Each property has a name (like a label) and a value (like the treasure inside). These properties are like the traits of your object — they define what it is.

let superhero = {
name: "Spider Man",
power: "Web Shooting",
weakness: "MJ",
};

In our superhero example, properties are things like “name,” “power,” and “weakness,” each with its own special value.

Internal Representation:

Now, let’s talk about the magic behind the scenes. Every object has some hidden stuff — we call them internal properties. They’re like the engine inside a car, making sure everything runs smoothly.

1. [[Prototype]]: The Family Connection

[[Prototype]] is like a family link. It helps objects share and inherit traits from each other. So, if one object knows a cool trick, others in its family can learn it too!

let superhero= {
name: "Spider Man",
power: "Web Shooting",
kill_mode: function() {
console.log("kill mode activated!!");
}
};

let peter_parker = Object.create(superhero);
peter_parker.power; // "Web Shooting"
peter_parker.kill_mode(); // "kill mode activated!!"

Here, the peter parker learns the cool tricks from super hero object through the [[Prototype]] link.

2. [[Extensible]]: Adding or Locking Up

[[Extensible]] is like deciding whether your object is open for more goodies or locked up. If it's set to ‘false’, no new stuff can be added.

let superhero= {
name: "Spider Man",
power: "Web Shooting",
}
};

Object.preventExtensions(superhero);

superhero.ability = "flying";

console.log(superhero); // { name: "Spider Man", power: "Web Shooting" }

By using Object.preventExtensions , we tell the object, "No more new stuff allowed!" It's like having a locked door.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Radha Priyadarshan
Radha Priyadarshan

Written by Radha Priyadarshan

0 Followers

Software Developer | AI Developer

No responses yet

Write a response