Just a question about Destructuring Assignment

Just a question about Destructuring Assignment
0

#1

Tell us what’s happening:

ok, it works, but what is the principal difference between this solution and good old:

  const len = str.length;

Your code so far
const {length:len} = str; // change this


function getLength(str) {
  "use strict";

  // change code below this line
  const {length:len} = str; // change this
  // change code above this line
  return len; // you must assign length to len in line

}

console.log(getLength('FreeCodeCamp'));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects/


#2

it’s just a new tool that will come in handy when certain situations warrant it.
There’s a whole topic on this in MDN if you want to read more.

for eg. for loops, while loops are very similar, but each one has its use in different scenarios.


#3

ok, I’ll try to get it later, thanks )