My stomach was so crampy yesterday. I’m not sure what I did to it. It almost feels like light food poisoning but I know I haven’t eaten anything that would have caused it. Today it’s feeling a bit better. I’ve eaten toast today. That’s how much I’ve been babying my stomach.
This weekend we are going to Denver to see the Angels game. And going to eat at In and Out cause we haven’t had that in so long. Too bad my aunt is out of town, it would have been great to see her. I’m excited to go on a road trip. My focus has been lacking today for coding. I packed earlier and waiting for Tommy to get home from work. I believe we are leaving tonight.
Tommy is having surgery on August 1st to have his discs in his neck replaced. I hope this surgery goes well and it helps him in the long run. He’s been in pain for a while.
JavaScript notes…
———————————
Destructuring assignment is special syntax introduced in ES6, for neatly assigning values taken directly from an object.
Consider the following ES5 code:
const user = { name: 'John Doe', age: 34 }; const name = user.name; const age = user.age;
name would have a value of the string John Doe, and age would have the number 34.
Here’s an equivalent assignment statement using the ES6 destructuring syntax:
const { name, age } = user;
Again, name would have a value of the string John Doe, and age would have the number 34.
Here, the name and age variables will be created and assigned the values of their respective values from the user object. You can see how much cleaner this is.
You can extract as many or few values from the object as you want.
Destructuring allows you to assign a new variable name when extracting values. You can do this by putting the new name after a colon when assigning the value.
Using the same object from the last example:
const user = { name: 'John Doe', age: 34 };
Here’s how you can give new variable names in the assignment:
const { name: userName, age: userAge } = user;
You may read it as “get the value of user.name and assign it to a new variable named userName” and so on. The value of userName would be the string John Doe, and the value of userAge would be the number 34.