Objects: Describing Things With Labels

Keys, values, and the secret identity of `console.log`. Thirteen short pages from Grade 8 of Middle School, about 15 minutes of reading in all.

What you’ll learn

  • What objects are and when to use them
  • Creating objects with keys and values
  • Dot notation vs bracket notation
  • Adding, changing and deleting properties
  • Methods, and a first look at this
  • Nested objects and arrays of objects
  • Looping over objects
  • Destructuring and shorthand
  • Copying objects (and the reference trap)
  • JSON: objects as text

The pages

Thirteen pages, about 15 minutes.

  1. What Is an Object? Arrays are brilliant for lists of similar things: a list of names, a list of scores, a list of foods. But what if you…
  2. Creating Objects You create an object with curly braces { }. Inside, you write key: value pairs, separated by commas. (Node prints…
  3. Reading Properties: Dot and Bracket Notation There are two ways to read a property from an object. The most common way is the dot: write the object's name, a dot…
  4. Adding, Changing and Deleting Properties Objects are flexible. You can change them any time, even if they were created with const (remember: const locks the…
  5. Methods: Functions Inside Objects Remember that functions are values (Grade 6)? That means a property's value can be a function. When a function lives…
  6. A First Look at this Methods often need to use the other properties of their own object. For example, a method that introduces a person…
  7. Nested Objects and Arrays of Objects Objects can contain other objects and arrays. And arrays can contain objects. You can nest them as deeply as you like…
  8. Looping Over Objects What if you want to go through every property of an object? Here are your options. The for...in loop visits every key…
  9. Shortcuts: Shorthand and Destructuring Modern JavaScript has a couple of lovely shortcuts for working with objects. If you're making an object from variables…
  10. Copying Objects (and the Reference Trap) In Grade 7, you saw that assigning an array to a new variable doesn't copy it. Objects work exactly the same way…
  11. JSON: Objects as Text Objects live in your program's memory. But what if you want to save an object to a file, or send it across the…
  12. Mini Project: The Report Card Generator Let's put objects, arrays, functions and loops together into something genuinely useful: a program that generates…
  13. Recap The key ideas of Grade 8, JavaScript objects, on one page. An object stores data as key: value pairs called…

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