Objects & properties
Keep related things together
Lesson 7 of 20 · 7 min · Module 3: Collections & meaningful data
An object groups related values under meaningful names. It is a small model of something in your program.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Group related values in an object
- Read properties with dot notation
- Use different records with the same function
The idea
Use curly braces to create an object. Access a property with a dot, such as profile.name. A function can read an object and return a useful result.
const profile = { name: "Alex", lessons: 4 };
console.log(profile.name);
01Keys give a value context
A name and a lesson count belong to the same profile. An object holds them under named properties, making the relationship clearer than two unrelated values.
const profile = { name: "Alex", lessons: 5 };
console.log(profile.name, profile.lessons);Alex 502Use the parameter you receive
describe(person) should read person.name and person.lessons. Reading the global profile instead would ignore other records passed into the function.
Your turn
profile with name: "Alex" and lessons: 5. Write describe(person) to return a message like "Alex has completed 5 lessons.".What the checks look for
- profile stores Alex and 5 lessons
- Describes Alex’s progress
- Works with a different person
Take this with you
Objects model related data; functions let the same behavior work with many records.