LESSON 21
Objects
Learning objective: Group related data with objects.
Understand
Objects store related values as key-value pairs.
An object groups related data under named keys (properties). Unlike arrays, order does not matter — you access values by name. Objects model real things like a user or a product.
Analogy: An object is like a labelled folder: each label (key) holds a piece of information.
See It in Action
Creating an object:
const user = {
name: "Sam",
age: 20
};
console.log(user.name); // SamHow it works:
user holds two properties; user.name reads the value stored under the name key.Try It Yourself
- Create an object describing a book.
- Log one of its properties.
- Add a third property.
Quick Quiz
How do objects store data?
Challenge
Model a product as an object with at least three properties.
Success condition: Your object holds named properties you can read.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →