Help me about destruction assignment

function getLength(str) {
“use strict”;

// change code below this line
const len=str; // change this
// change code above this line

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



Can you format your code and add a link to the exercise?

thats the link to the challenge

Hey @zeshan880,
Javascript is an object oriented language.
So, even the string is an object in javascript.
Now, think of string as any normal object and length as its one of the properties.

var string  = {
   "length" : 6

Now read the instruction in the challenge carefully.
They want this length property of str object to be assigned to the len variable.
Try solving now.
Does that help?

1 Like


Think about len as an object, if it is an object then, it has properties, in this case your object const len has 1 property that should be length so, remember from previous lessons how to assign a value to an object property, that is: = “value”

Implement the same but with the challenge being:
const len => Object
length => property of “len” object
str.length => value to assign to len.length

Hope this helps!

1 Like

i cant solve it i had tried a lot

Could you post your latest code?

This should work:

// change code below this line

const { length: len } = str; // change this

// change code above this line

After reading the challenge, you should have noted that you are using destructing variables assignment. The code above can translate to this:

Assign the value of the property length to the variable len searching from the object str.

Hope this helps!

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution.


Sorry about that, didn’t know it could not be posted.

It is just preferred for the FCC challenges, to give guidance and give the OP a chance to figure it out on his/her own.