Modern JS methods
Sun Jun 30 2024 00:44:03 GMT+0000 (Coordinated Universal Time)
Saved by
@NoFox420
#javascript
We are going to use a method called Object.freeze(obj) which will freeze this object and prevent any changes being made to it.
In the last two steps, you have been accessing properties from the myFavoriteFootballTeam object using dot notation and assigning them to new const variables. But in JavaScript, there is an easier way to accomplish the same goal.
The object destructuring syntax allows you to unpack values from arrays and objects:
const developerObj = {
name: "Jessica Wilkins",
isDeveloper: true
};
// Object destructuring
const { name, isDeveloper } = developerObj;
Function parameters can be initialized with default values. If a function is called without an argument, then the default value will be used:
const greeting = (name = "Anonymous") => {
return "Hello " + name;
}
console.log(greeting("John")); // Hello John
console.log(greeting()); // Hello Anonymous
content_copyCOPY
Comments