Bookcliff / learning

2 stars 0 forks source link

Learn about object destructing and array destructing #5

Closed Bookcliff closed 2 years ago

Bookcliff commented 2 years ago
RusseII commented 2 years ago

You can close this once you can answer the following questions:

RusseII commented 2 years ago

Use object destructuring when you need to separate out properties, values, etc. held within the object. This is helpful when you need to parse out a specific property from an object (or value from array).

Yes. Are you able to write a few examples of object destructuring here?

Bookcliff commented 2 years ago

const arr = [1, 2]; const [a, b] = arr;

console.log(a); // 1 console.log(b); // 2

const russell = { age: 25, gender: 'male' };

const {age, gender} = russell; console.log(age); // 25 console.log(gender); // male

RusseII commented 2 years ago

Amazing. Importing files works the same way. Depending on how a component is imported you do either

import {button} from './file' vs import button from './file'