Nested Objects, Getters & Setters, and Factory Functions — Day 30

Today’s internship session at Cudose Creative Agency stretched my brain in new ways. We went deeper into Objects, exploring how data can be structured inside other data, how to control access to object properties, and how to generate objects efficiently using factory functions.
This was one of those days where JavaScript felt powerful… and slightly disrespectful 😭.
---
🔥 What We Covered Today
1️⃣ Nested Objects
Objects inside objects — the moment things start looking like a JSON family tree.
const user = {
name: "Jordan",
address: {
city: "Abuja",
street: "Tech Road",
zip: 900001
}
};
We talked about how to access deeply nested values and how this structure makes real-world data more organized.
---
2️⃣ Looping Through Objects (for…in syntax)
We explored the for…in loop for iterating over object keys:
for (let key in user) {
console.log(key, user[key]);
}
Super useful for inspecting objects — especially when working with nested structures.
---
3️⃣ Protected Properties — Getters & Setters
This was the part that made me question JavaScript’s intentions 😭.
Getters and setters help you control how object properties are read or changed:
const person = {
_age: 20,
get age() {
return this._age;
},
set age(value) {
if (value > 0) this._age = value;
}
};
The underscore (_age) signals: “Don’t touch this. Talk to my getter/setter instead.”
A clean way to enforce rules inside objects.
---
4️⃣ Factory Functions
Instead of repeating object structures manually, factory functions help you create multiple similar objects:
function createUser(name, level) {
return {
name,
level,
greet() {
console.log(`Hello ${this.name}`);
}
};
}
const u1 = createUser("Jordan", "Intern");
They’re reusable, scalable, and remove redundancy — perfect for larger apps.
---
🧠 Key Takeaways
Nested objects make data easier to structure but harder to navigate if you’re not careful.
for…in helps you loop through object keys cleanly.
Getters and setters give you safe, controlled access to object values.
Factory functions are cleaner alternatives to constructor functions for many use cases.
---
🚀 Final Thoughts
Today felt like learning the “adult” side of JavaScript objects — data protection, object generation, and structured access. These patterns make real-world applications manageable, and understanding them early is a big win.
Excited (and slightly scared 😭) for what’s coming next.



