Skip to content

Instantly share code, notes, and snippets.

@jmcmaster
Created May 11, 2018 15:06
Show Gist options
  • Select an option

  • Save jmcmaster/2fd3689a556f14e4221e1a56aeb238fa to your computer and use it in GitHub Desktop.

Select an option

Save jmcmaster/2fd3689a556f14e4221e1a56aeb238fa to your computer and use it in GitHub Desktop.
Named Params Destructuring
function display({data, error, loading}) {
if (loading) {
return "Loading...";
}
if (error) {
return error.message;
}
return `Hello ${data.name}`;
}
const res1 = display({loading: true})
const res2 = display({error: {message: "this is an error"}})
const res3 = display({data: {name: 'World'}})
console.log(res1, res2, res3);
// ------------------
function sayHi([first, last]) {
return `Hi ${first}`
}
const res4 = sayHi(['Jason', 'McMaster'])
console.log(res4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment