Codington
0 of 8 problems solved • 0%

Exercise prompt

Extract Object Properties

Object destructuring reads properties into variables with matching names.

Example

const book = { title: "Dune", pages: 412 }; const { title, pages } = book; console.log(title, pages); // Output: // Dune 412
  • title receives book.title: "Dune".
  • pages receives book.pages: 412.

Names determine which properties are read; { pages, title } would give the same values.

Predict the output

A course card extracts fields in a different order from their declaration. Predict the printed values.

const course = { lessons: 12, title: "JavaScript" }; const { title, lessons } = course; console.log(title, lessons);
What will this code print?