Skip to content

Instantly share code, notes, and snippets.

@micahriggan
Created March 26, 2019 03:08
Show Gist options
  • Save micahriggan/869d42a2e22a105fc491c1882ef11fc9 to your computer and use it in GitHub Desktop.
Save micahriggan/869d42a2e22a105fc491c1882ef11fc9 to your computer and use it in GitHub Desktop.
Simple examples of destructuring params
function log(...args) {
console.log(args);
}
function getName({name}) {
console.log(name);
}
function pop([first, ...rest]) {
return rest;
}
function push(array, elem) {
return [...array, elem];
}
function test1() {
log("Hello", "World")
}
function test2() {
getName({name: 'Micah', points: 100});
}
function test3() {
console.log(pop(["First", "Second", "Third"]));
}
function test4() {
console.log(push(["First"], "Second"));
}
test1();
test2();
test3();
test4();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment