Last active
October 29, 2018 17:23
-
-
Save talha08/6ae71b7f2091d8ed9e35ce7ffce5b1ca to your computer and use it in GitHub Desktop.
ES6 Object Destructuring
This file contains hidden or 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
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