ES6 - Use Destructuring Assignment to Assign Variables from Objects

function getLength(str) {
“use strict”;

// change code below this line
const length = 0; // change this
// change code above this line

return len; // you must assign length to len in line



share the challenge link

1 Like

I think you will help me thz

The instructions for this challenge are a little hard to understand. Below is a link to a post I made the other day about this. Hope that helps some

1 Like

Ok so you need to assign the length of the str to len ,keep in mind only assign the length of str.

const { x : a} = vowel

where a is the varible to store the vowel x and vowel itself is the varibale from which we are using the vowel x.
Just think for a while it it.


Hay how to you write code , please show that code
i can’t that solution , what it is destructuring with reassignment was used ?

Thank you for the explanation it was really useful. I really found the question confusing.:grinning:

1 Like

Thanks this was really helpful!

Having a string object as the introduction to destructuring assignment is pretty confusing.

Essentially, to solve this, you need to first know that the string have properties, and sort of think of them as key:value pairs. I don’t remember when we were shown in depth how the string object works.

1 Like

Back in Basic JavaScript: Find the Length of a String lesson

It was not necessary to give an in-depth discussion about the string object, but you were made aware of strings having properties. I agree though the challenge here approaches it from something more abstract.


Now I see that it mentioned length as a property, which could be easily overlooked. The next part to wrap my head around was associating property as a key value pair.

I think the above makes this lesson’s task extra convoluted, given that it was a start of another concept.