Last active
August 21, 2018 13:39
-
-
Save bernbecht/800a345d5e43f030af308431682cd6a3 to your computer and use it in GitHub Desktop.
Learn ES6 /Variables and Parameters
This file contains 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
console.clear(); | |
/////////////////////// | |
// Destructure | |
// | |
console.log('///////////////////////\n// Destructure\n///////////////////////'); | |
{ | |
let doWork = ()=> { | |
return { | |
firstName: 'Bernardo', | |
lastName: 'Bechtold', | |
handles: { | |
twitter: 'Berhell' | |
} | |
} | |
} | |
let { | |
firstName: first, | |
lastName: last, | |
handles: {twitter: twitterAccount} | |
} = doWork(); | |
console.log(first); | |
console.log(last); | |
console.log(twitterAccount); | |
} | |
/////////////////////// | |
// Default Parameter | |
// | |
console.log('///////////////////////\n// Default Parameter\n///////////////////////'); | |
{ | |
let doWork = (url, {data = 'data', cache = 'cache'}) => { | |
return { | |
data: data, | |
cache: cache | |
} | |
} | |
let { | |
data, | |
cache | |
} = doWork('api/test', {}); | |
console.log(data); | |
console.log(cache); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment