Skip to content

Instantly share code, notes, and snippets.

@softwarespot
Last active September 30, 2015 06:19
Show Gist options
  • Select an option

  • Save softwarespot/be5848179eb45443c7d2 to your computer and use it in GitHub Desktop.

Select an option

Save softwarespot/be5848179eb45443c7d2 to your computer and use it in GitHub Desktop.
ES2015 destructuring
function destructuring( {weight, age, space = null }) {
// Instead of using something like opts.weight, now just use the property name in the function signature
console.log(weight);
console.log(age);
// Checking for null, standard ES5, as ?? isn't present in ES2015
console.log(space ? space : 'Space not set');
}
// Block scoped variable using let/const
const age = 30;
// Age is basically set as age: age behind the scenes
destructuring({ weight: 82, age });
// Notice how the params are passed differently than how they're set in the signature?
const weight = 100;
destructuring({ age: 21, space: 'Some space', weight });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment