De-structuring Flashcards

1
Q

What is destructuring, conceptually?

A

Assigning a property of an object to a variable.

variable name of destructuring should match property name of object pulling info from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax for Object destructuring?

A

const {property : variable} = object

if variable has same name as property, just write the name.

able to assign value of properties.
able to give a property an unassigned property value.
person = {
currentAge:28
}
{currentAge: age = 18 } = person
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the syntax for Array destructuring?

A

const [variable at index] = array

let [x, y, z] = getScores();

console. log(x); // 70
console. log(y); // 80
console. log(z); // 90

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

creating curly brackets right side

destructuring curly brackets left side

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to destructure a null object

A

let { firstName, lastName } = getPerson() || {};

use the or operator, firstName, lastName will return undefined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly