×

javascript · level 2 · unit 5 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An keeps related values together, each with a label.

An array is a numbered list. Often you want labels instead: a pet's name, age and favourite toy. An object holds those values together, each under its own , like a form with a labelled box for every answer.

Write an object in curly brackets: { name: "Rex", age: 3 }. Each key is followed by a colon and its value, and commas separate the pairs. Read a value with a dot and its key: pet.name.

The event your listeners catch is an object too. That is why event.target works.

const pet = { name: "Rex", age: 3, toy: "squeaky ball" };
console.log(pet.name);
console.log(`${pet.name} is ${pet.age} and loves his ${pet.toy}.`);
console.log(pet);

The console shows a whole object with every key in double quotes. That is how Gwecode prints objects.