File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
Sprint-1/destructuring/exercise-1 Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ const personOne = {
66
77// Update the parameter to this function to make it work.
88// Don't change anything else.
9+ // Use object destructuring in introduceYourself parameter
910function introduceYourself ( { name, age, favouriteFood } ) {
10- // Use the destructured variables in the console.log statement.
11- // Don't change anything else.
11+
1212 console . log (
1313 `Hello, my name is ${ name } . I am ${ age } years old and my favourite food is ${ favouriteFood } .`
1414 ) ;
Original file line number Diff line number Diff line change @@ -29,5 +29,27 @@ console.log(`Batman is ${firstName}, ${lastName}`);
2929
3030# Exercise
3131
32- - What is the syntax to destructure the object ` personOne ` in exercise.js?
33- - Update the parameter of the function ` introduceYourself ` to use destructuring on the object that gets passed in.
32+ 1 - What is the syntax to destructure the object ` personOne ` in exercise.js?
33+
34+ For the personOne example, the destructuring syntax would be:
35+
36+ ```
37+ let { name, age, favouriteFood } = personOne;
38+
39+ That pulls the three properties out of personOne into separate variables.
40+
41+ ```
42+ 2 - Update the parameter of the function ` introduceYourself ` to use destructuring on the object that gets passed in.
43+
44+ ```
45+ To update the parameter of introduceYourself function to use destructuring, I would write:
46+
47+ function introduceYourself({ name, age, favouriteFood }) {
48+ console.log(
49+ `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
50+ );
51+ }
52+ This way, the function immediately unpacks those properties from the object is passed in, without
53+ needing separate variable assignments.
54+
55+ ```
You can’t perform that action at this time.
0 commit comments