LESSON 22
Object Properties
Learning objective: Read, add, and update object properties.
Understand
Object properties can be accessed and changed.
Read properties with dot notation (user.name) or bracket notation (user['name']). You can add new properties, update existing ones, and loop over them. Bracket notation is handy when the key is in a variable.
Analogy: Accessing a property is like opening one drawer in a labelled cabinet.
See It in Action
Updating and adding:
const user = { name: "Sam" };
user.age = 21; // add
user.name = "Samuel"; // updateHow it works: Assigning to a new key adds a property; assigning to an existing key updates it.
Try It Yourself
- Read a property with dot notation.
- Add a new property.
- Update an existing property.
Quick Quiz
When is bracket notation especially useful?
Challenge
Take an object and add one property while updating another.
Success condition: Your object reflects both the added and updated properties.
+10 XP
Lesson Complete
You answered correctly and completed the required practice. Your progress has been saved on this device.
Continue to next lesson →