Skip to content

Instantly share code, notes, and snippets.

@bosr
Created September 9, 2017 10:56
Show Gist options
  • Save bosr/6b4684d947d42395bfb9330bea1acaf5 to your computer and use it in GitHub Desktop.
Save bosr/6b4684d947d42395bfb9330bea1acaf5 to your computer and use it in GitHub Desktop.
'use strict';
let widgets = ['widget1', 'widget2', 'widget3', 'widget4', 'widget5'];
let [a, b, c, ...d] = widgets;
console.log(a); // logs widget1
console.log(b); // logs widget2
console.log(d); // logs ['widget4', 'widget5']
'use strict';
function getData({ url, method = 'post' } = {}, callback) {
callback(url, method);
}
getData({ url: 'myposturl.com' }, function (url, method) {
console.log(url, method);
});
getData({ url: 'myputurl.com', method: 'put' }, function (url, method) {
console.log(url, method);
});
// logs
// myposturl.com post
// myputurl.com put
'use strict';
let parentObject = {
title: 'Super Important',
childObject: {
title: 'Equally Important'
}
}
let { title, childObject: { title: childTitle } } = parentObject
console.log(childTitle);
// log: Equally Important
'use strict';
let toybox = { item1: 'car', item2: 'ball', item3: 'frisbee' };
let {item1, item2} = toybox;
console.log(item1, item2);
// logs: car ball
let {item3: disc} = toybox;
console.log(disc);
// logs: frisbee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment