Skip to content

Instantly share code, notes, and snippets.

@talha08
Last active October 29, 2018 17:23
Show Gist options
  • Save talha08/6ae71b7f2091d8ed9e35ce7ffce5b1ca to your computer and use it in GitHub Desktop.
Save talha08/6ae71b7f2091d8ed9e35ce7ffce5b1ca to your computer and use it in GitHub Desktop.
ES6 Object Destructuring
const student = {
firstname: 'Jhon',
lastname: 'Snow',
country: 'England',
ielts_scores: {
speaking: 8,
listening: 7.5,
writing: 8.5,
reading: 7.0
}
};
//Old Style
const firstname = student.firstname;
const lastname = student.lastname;
const country = student.country;
const ielts_scores = student.ielts_scores;
console.log(`Old method: ${firstname}, ${lastname}, ${country}`) //"Old Style: Jhon, Snow, England"
//ES6 Style
const { firstname, lastname, country, ielts_scores } = student;
console.log(`New method: ${firstname} ${lastname} ${firstname}`) //"ES6 Style: Jhon, Snow, England"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment