Created
July 15, 2020 04:32
-
-
Save matheusmurta/67fbfd1381f9f912ad502b40fad54b7d to your computer and use it in GitHub Desktop.
ES6 Destructuring
This file contains 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 = { | |
name: 'John Doe', | |
age: 16, | |
scores: { | |
maths: 74, | |
english: 63 | |
} | |
}; | |
// We define 3 local variables: name, maths, science | |
const { name, scores: {maths, science = 50} } = student; | |
const person = { | |
name: 'John Doe', | |
country: 'Canada' | |
}; | |
// Assign default value of 25 to years if age key is undefined | |
const { name: fullname, country: place, age: years = 25 } = person; | |
// Here I am using ES6 template literals | |
console.log(`I am ${fullname} from ${place} and I am ${years} years old.`); | |
https://codeburst.io/es6-destructuring-the-complete-guide-7f842d08b98f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment