Recap

Grade 8, page 13 of 13. A one-minute read.

  • An object stores data as key: value pairs called properties: { name: "Omar", age: 17 }.
  • Read properties with dot notation (obj.key) or bracket notation (obj["key"] or obj[variable]).
  • Missing properties give undefined. Reading a property of undefined throws a TypeError.
  • Add or change properties by assigning to them. Remove them with delete. Check for them with in.
  • A function stored in an object is a method. Inside a method, this refers to the object. Don't use arrow functions as methods.
  • Objects and arrays can be nested inside each other. Arrays of objects are the most common data shape.
  • Loop over keys with for...in, or use Object.keys, Object.values and Object.entries.
  • Shorthand: { name } means { name: name }. Destructuring: const { name, age } = person;
  • Objects are stored by reference. b = a shares the object. Copy with { ...a }, merge with { ...a, ...b }.
  • JSON is text that represents objects. Use JSON.stringify and JSON.parse to convert.

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning