Sikau

JavaScript · Day 36 · about 25 min

Objects

A contact card with labelled fields.

Things with details

A contact in your phone has a name, a number, maybe a birthday. These details belong together. An object groups related values under labels, like a filled-in card.

Making an object

const friend = {
  name: "Pemba",
  city: "Namche",
  age: 24,
  likesTea: true,
};

console.log(friend);
console.log(friend.name);
console.log(friend.age + 1);

Array vs object: An array is a numbered shelf — you find things by position. An object is a filing cabinet with labelled drawers — you find things by name.

The rest of this lesson

  • Objects describe real thingsexplain
  • Predict the outputpredict
  • Reading an objectpredict
  • Build a contactfill
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript