JavaScript has me confused. I have to spend more time reading up on certain things since the program only gives one example per “section.”
I just remembered that I have a few friends that I still need to text back. The introvert in me tends to forget that I need to keep in touch with people.
This weekend we got some new furniture for the house. Tommy wants to work on upgrading and organizing the house. We need some good storage. I like the new furniture, it looks nice and I think it will make it easier to keep the area clean.
I don’t have much to chat about today. It’s been a pretty quiet day. Which is pretty amazing for having the boys and Karissa home. But they are just doing their own thing. I had Karissa do my laundry and I’m in the process now of putting the clothes away. Alex is doing his laundry and it looks like he is doing his entire wardrobe. I swear he does his laundry every two weeks and it takes him all day and sometimes to the next day. We have to change that.
I’m about to start dinner soon. Hamburger soup.
JavaScript notes…
———————————–
As seen in the previous challenge, const declaration alone doesn’t really protect your data from mutation. To ensure your data doesn’t change, JavaScript provides a function Object.freeze to prevent data mutation.
Any attempt at changing the object will be rejected, with an error thrown if the script is running in strict mode.
let obj = { name:"FreeCodeCamp", review:"Awesome" }; Object.freeze(obj); obj.review = "bad"; obj.newProp = "Test"; console.log(obj);
The obj.review and obj.newProp assignments will result in errors, because our editor runs in strict mode by default, and the console will display the value { name: “FreeCodeCamp”, review: “Awesome” }.
In JavaScript, we often don’t need to name our functions, especially when passing a function as an argument to another function. Instead, we create inline functions. We don’t need to name these functions because we do not reuse them anywhere else.
To achieve this, we often use the following syntax:
const myFunc = function() { const myVar = "value"; return myVar; }
ES6 provides us with the syntactic sugar to not have to write anonymous functions this way. Instead, you can use arrow function syntax:
const myFunc = () => { const myVar = "value"; return myVar; }
When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword return as well as the brackets surrounding the code. This helps simplify smaller functions into one-line statements:
const myFunc = () => "value";
This code will still return the string value by default.