JJ Day 14: Unlocking Objects

Rabee AmanRabee Aman
3 min read

Today was about Objects. They are a crucial part of JavaScript and anyone who works on a real project will inevitably bump into them. Objects are everywhere. They are a massive topic, but for now, TOP focused on the basics.

What Are Objects?

JavaScript has 8 main data types. Seven of them are called primitive types. These are things like numbers, strings, booleans, and so on. The reason they are called primitive is that they hold only a single value.

Objects, on the other hand, are special. They can hold multiple values in a structured way by pairing two things: a key and a value.

Think of it like a supermarket. Every item on the shelf has a barcode. The barcode is the key, and the actual product is the value. This pairing makes objects super handy when it comes to storing and grouping data.

Creating an Object

To create an object, curly brackets are used. Here’s a nice and simple empty object:

let dish = {};

This line creates an empty object called dish. At this point, it has no properties. It’s like an empty supermarket shelf waiting to be stocked.

Let’s add some properties:

let dish = {
  name: "pasta",
  origin: "italy"
};

Now our dish object has two properties:

  • name with the value "pasta"

  • origin with the value "italy"

Accessing Properties

Accessing the values inside an object is straightforward. The most common way is the dot notation.

dish.name

This will return "pasta". You simply ask the object to give you the value of the property called name.

Flexibility of Values and Keys

One of the coolest things about objects is that the values can be almost anything. Numbers, strings, booleans, arrays, even other objects. This makes them powerful building blocks in JavaScript.

But the flexibility does not stop there. Even the keys can be surprising. Property names are usually simple words, but they can actually be reserved words too. You could name a property "return" or "for" and JavaScript would still accept it. Of course, it is not a great idea in real-world coding, but the language allows it.

Why Objects Matter

Objects are the foundation of most things in JavaScript. They let you store, organize, and retrieve data in a way that is logical and efficient. If primitive data types are the raw ingredients, objects are the recipe that ties them together into a dish that actually makes sense.

Final Thoughts

I feel like I’ve just unlocked a new form of storage. Instead of trying to juggle random bits of data, I now have a structured way to keep them together. Today was only the beginning.

0
Subscribe to my newsletter

Read articles from Rabee Aman directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rabee Aman
Rabee Aman