Destructuring assignment

PHOTO EMBED

Thu Jul 13 2023 14:55:59 GMT+0000 (Coordinated Universal Time)

Saved by @patidar__mohan #javascript

// we pass object to function
let options = {
  title: "My menu",
  items: ["Item1", "Item2"]
};

// ...and it immediately expands it to variables
function showMenu({title = "Untitled", width = 200, height = 100, items = []}) {
  // title, items – taken from options,
  // width, height – defaults used
  alert( `${title} ${width} ${height}` ); // My Menu 200 100
  alert( items ); // Item1, Item2
}

showMenu(options);
content_copyCOPY

https://javascript.info/destructuring-assignment