Skip to the content

Choosing the structure

JavaScript · Unit 8: More on arrays

An array is a line: order matters, repeats are fine and you read by position.

An object describes a single thing with properties you know ahead of time: the name, the age, the price.

const line = ["Ava", "Leo", "Ava"];
const film = { title: "Coco" };
console.log(line[2], film.title);

Prints

Ava Coco

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

    You store the songs for the party in the order they'll play, and a song can play twice. What do you use?

  2. 2. Multiple choice

    You store the details of a phone, its brand, its price and its memory. What do you use?

  3. 3. Complete the code

    Complete it with the structure that describes a film.

  4. 4. Multiple choice

    In a sign-up, each email can be registered only once, and you need to know quickly if one is already there. Which structure does that on its own?

  5. 5. Predict the output

    What does this code print?

  6. 6. Find the bug

    This program should print how many different people voted, "Voters: 2". Which line has the error?

  7. 7. Put the lines in order

    Order the function that returns the first name that lines up twice, or "Nobody" if no one repeats.

  8. 8. Multiple choice

    What's a real reason to prefer a Map over an object?

  9. 9. Find the case that fails

    countDistinct(vals) should return how many different values there are. The number 1 and the string "1" count as different. Which call does it fail with?

  10. 10. Predict the output

    You put several structures together. What does it print?

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 →