var voxel = {x: 3.6, y: 7.4, z: 6.54 };
var x = voxel.x; // x = 3.6
var y = voxel.y; // y = 7.4
var z = voxel.z; // z = 6.54
Ok awesome. An object with key value pairs, that we are then assigned to global variables. I know this! But then…
Here’s the same assignment statement with ES6 destructuring syntax:
const { x, y, z } = voxel; // x = 3.6, y = 7.4, z = 6.54
What? Thats not at all what the previous code was. First the keys don’t have values. So x shouldn’t be 3.6. Second no global variables are being assigned to anything. This is literally just equal to this:
const Obj = {x,y,z};
Aka an object with declared keys (no values).
I am so stuck. Read the ntructions like 20 times and I still have 0 clue about what I have to do.
Ok. I took a break. Calmed downed, and read the MDN entry on Destructuring assignment. Saw some videos and I kind of got it.
Correct me if I am wrong. This ES6 feature is used to assign object values to external variables. Yes?
Anyhow, this is my new code and its still wrong:
function getLength(str) {
"use strict";
// change code below this line
const length = {x: str.length};
const {x : len} = length; // change this
// change code above this line
return len; // you must assign length to len in line
}
console.log(getLength('FreeCodeCamp'));
this code was super well explained if you arent getting it dot just ask for the answer track the variables and try to understand the syntax for what is going on.