Skip to content

Instantly share code, notes, and snippets.

@thomhos
Last active October 17, 2016 12:37
Show Gist options
  • Save thomhos/ecae33d81f3f53ab4f8bc04714979161 to your computer and use it in GitHub Desktop.
Save thomhos/ecae33d81f3f53ab4f8bc04714979161 to your computer and use it in GitHub Desktop.
Destructuring
// Basics
fn = ({name, color}) => console.log(name, color); // logs: foo bar
fn = ([name, color]) => console.log(name, color); // logs: foo bar -- in case it comes from an array (by index)
// Renaming
fn = ({ first: firstName }) => console.log(firstName); // logs: foo
// Defaults
fn = ({ name = 'John', age = 12 } = {}) => console.log(name, age);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment