Object Destructuring in JavaScript

Level 3134 keystrokes

Uses object destructuring to extract multiple properties into separate variables.

JavaScript code

// Create an object with three properties
1const person = {
2 name: "Alice",
3 age: 25,
4 city: "Tokyo"
5};
// Destructuring copies the properties into variables of the same name
// name = "Alice", age = 25, city = "Tokyo"
6const { name, age, city } = person;
// The template literal embeds the values: "Alice, 25, Tokyo"
7console.log(`${name}, ${age}, ${city}`);

Output

Alice, 25, Tokyo
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ,× 6
  • {× 5
  • }× 5
  • "× 4
  • ;× 3
  • :× 3
  • $× 3
  • `× 2
  • =× 2
  • .× 1

More JavaScript examples at level 3

← JavaScript typing practice