Objects in JavaScript

Objects = how to group related values by name.

This chapter has 2 lessons and 10 exercises you run and check in your browser. Plan on about 44 minutes.

After this chapter, you can:

  • Describe one product or customer as an object.
  • Read, change, add and delete properties safely.
  • Give objects methods that use this.
  • Copy, merge and update objects without changing the original.

Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.

Before you start, finish Arrays.

Next chapter: Data Handling.

Lessons in this section

  1. Object Fundamentals

    What an object is, creating one with a literal or new Object(), dot and bracket access, updating, adding and deleting properties, methods and this, checking a property with in, and looping with for...in.

    • Describe an object as a set of key-value pairs
    • Create an object with a literal and with new Object()
    • Choose between dot and bracket notation
    • Update, add and delete properties
  2. Object Operations

    Nested objects and safe reads with ?., destructuring with defaults, copying and combining with spread, collecting leftovers with rest, shallow versus deep copies, computed keys, and immutable updates with const and Object.freeze.

    • Read a value several levels inside a nested object
    • Guard a nested read with optional chaining
    • Destructure properties into variables with default values
    • Copy and combine objects with spread