JavaScript AcademyProfessional Engineering

Learning object 28 of 100

Destructuring visualizer

Step through destructuring statements and watch each variable receive its value, its default or undefined.

Loading…

What it shows

Object patterns match by name and array patterns match by position. A colon renames ({ title: heading }), and = supplies a default that is used only when the value is undefined. Parameter patterns work the same way at every call.

Guided experiment

  1. In Objects, step past the destructuring line. Which variables appeared?
  2. In Defaults, explain why one default was used and the other was not.
  3. In Parameters, call describe with a different object.

Predict

const [a, b = 5] = [1, null]; What is b?

Related

Lessons: Lesson 41: Destructuring

Projects: Project 9: Shopping Cart Price Calculator

Source: web/assets/js/objects/object-028.js in the companion repository.