Syncing account progress…

Back

Beginner · 8 min

Describe data with objects

Group related values under named properties.

Name each property

An object groups related data inside braces. Each property has a name and a value, separated by a colon. Dot notation reads a named property.

const book = { title: "Small Steps", pages: 120 };
console.log(book.title);
console.log(book.pages);

Output

Small Steps
120

Update a property

You can change an object property even when the object is stored with const. A missing property returns undefined.

const item = { name: "Notebook", stock: 5 };
item.stock = 4;
console.log(item.stock);
console.log(item.color);

Output

4
undefined

Put it into practice

  1. Predict the output of each example before running it.
  2. Complete the coding task, then try the practice questions.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Calculate an item cost

Set total to item.price multiplied by item.quantity, then display total.

Practice