freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../es6/use-destructuring-assignmen.../index.md

21 lines
855 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Use Destructuring Assignment to Assign Variables from Objects
---
## Use Destructuring Assignment to Assign Variables from Objects
# This challenge requires some intuition about string objects in javascript.
When you create a string object it is based on the following <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype">string prototype</a>.
Thus, each string has a length property; genericString = {length: 13}. (This is the only adopted property from the String.prototype.)
# Reassign properties using deconstruction.
```javascript
2018-11-12 07:12:31 +00:00
var basicObj = {x: 40};
2018-10-12 19:37:13 +00:00
//To reassign 'get the value of the x property of basicObj and place its value into bigX' in ES6:
2018-11-12 07:12:31 +00:00
const { x: bigX } = basicObj;
console.log(bigX) // ans = 40
2018-10-12 19:37:13 +00:00
```
Place the value of the length property of 'str' into len.