Skip to content

Instantly share code, notes, and snippets.

@AsaAyers
Created October 8, 2015 01:29
Show Gist options
  • Save AsaAyers/46f2a408e8f40d194e3e to your computer and use it in GitHub Desktop.
Save AsaAyers/46f2a408e8f40d194e3e to your computer and use it in GitHub Desktop.
const someObject = {
a: "Some Value"
// ^ Input
// ^ Output: someObject.a
}
const { a: a } = someObject
// ^ Output: `const a`
// ^ Input: someObject.a
// When the key and value are the same you can just use one:
const b = 'B'
const nextObject = { b }
// ^ Input/Output: `nextObject = { b: b }`
console.assert(nextObject.b === b) // true
// LOOK! I can create a new scope to avoid declaring the same variable twice!
{
const { b } = someObject
// ^ Input/Output: `const b = someObject.b`
console.assert(b === nextObject.b)
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment