Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created April 18, 2018 08:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gladchinda/4fc90ded5d51ed78069037259e64a9e3 to your computer and use it in GitHub Desktop.
Save gladchinda/4fc90ded5d51ed78069037259e64a9e3 to your computer and use it in GitHub Desktop.
// Initialize local variables
let country = 'Canada';
let firstname = 'John';
let lastname = 'Doe';
const student = {
firstname: 'Glad',
lastname: 'Chinda',
country: 'Nigeria'
};
// Reassign firstname and lastname using destructuring
// Enclose in a pair of parentheses, since this is an assignment expression
({ firstname, lastname } = student);
// country remains unchanged (Canada)
console.log(firstname, lastname, country); // Glad Chinda Canada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment