Skip to the content

Creating and reading

JavaScript · Unit 7: Objects

An object stores data by name. It goes inside braces {} and each piece of data is a property: the name, a colon and the value, with commas between them.

If it doesn't fit on one line, you write one property per line.

const ava = {
  name: "Ava",
  age: 17,
};
console.log(ava);

Prints

{ name: 'Ava', age: 17 }

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Multiple choice

    Which of these lines creates an object with two properties?

  2. 2. Predict the output

    What does this code print?

  3. 3. Complete the code

    Complete it to print Mia's age.

  4. 4. Predict the output

    What does this code print?

  5. 5. Find the bug

    This program should print the price of the item asked for, 5. Which line has the error?

  6. 6. Predict the output

    What does this code print?

  7. 7. Predict the output

    Look closely at the capital letter. What does it print?

  8. 8. Put the lines in order

    Order the lines to print how many hours the movie lasts, with one decimal.

  9. 9. Predict the output

    What does this code print?

  10. 10. Find the case that fails

    greet(p) should return "Hi, " plus the person's name, or "Hi, friend" if the object has no name. Which call makes it fail?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →