Created
June 28, 2018 02:36
-
-
Save MostlyFocusedMike/7bf44ef6a1c9a0f1752eb3fada655995 to your computer and use it in GitHub Desktop.
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
let user = { | |
paid: true, | |
attributes: { | |
id: 43020233, | |
description: { | |
name: "tom", | |
age: 23, | |
level: 2 | |
} | |
} | |
} | |
// without variables this is what we must do | |
console.log(user.attributes.description.name) | |
// OPTION 1 | |
// lets try assigning them to variables: | |
let name = user.attributes.description.name | |
let age = user.attributes.description.age | |
let level = user.attributes.description.level | |
console.log(name) | |
// This is terrible because I have to write it out so many times | |
// OPTION 2 | |
// let's try a shorter way: | |
let description = user.attributes.description | |
name = description.name | |
age = description.age | |
level = description.level | |
console.log(name) | |
// that's marginally less typing, but still bad | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment