Last active
October 17, 2016 12:37
-
-
Save thomhos/ecae33d81f3f53ab4f8bc04714979161 to your computer and use it in GitHub Desktop.
Destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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