// 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);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter