Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

destructuring function nested parameters

let options = {
  title: 'My menu',
  items: ['item1', 'item2']
};

function showMenu({
  title = 'Untitled',
  width: w = 100,
  height: h = 200,
  items: [item1, item2] = ['something', 'esle'] // default whole array
  /*
  	items: [item1 = 'something', item2 = 'else']  // default items
  */
} = {} /* default empty obj if showMenu() doesn't get an argument */ ) {
  console.log(`${title} ${w} ${h}`);
  console.log(`${item1} and ${item2}`);
}

showMenu(options);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #destructuring #function #nested #parameters
ADD COMMENT
Topic
Name
6+7 =