Last active
September 30, 2015 06:19
-
-
Save softwarespot/be5848179eb45443c7d2 to your computer and use it in GitHub Desktop.
ES2015 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
| 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