Theme
Primary Color
Lesson 13

Destructuring Object Part 2

محتوى الدرس

main.js
/*
  Destructuring
  - Object
  - Array
  - Parameter
*/

// First Example

const user = {
  name: 'Osama',
  gender: 'Male',
  age: 36,
  city: 'Cairo',
  website: 'Elzero',
  theme: 'red'
};

const {name: theName, gender: theGender, age: theAge, theme: theTheme = 'Default'} = user;

console.log(`My Name Is: ${theName}, Iam ${theGender}, My Age Is: ${theAge}, My Theme Color Is: ${theTheme}`);

// ###########################

// Second Example

const user = {
  name: 'Osama',
  gender: 'Male',
  age: 36,
  city: 'Cairo',
  website: 'Elzero',
  theme: 'Default',
  langs: {
    html: '70%',
    css: '80%',
    js: '10%',
    python: '20%'
  }
};

const {html, css, js} = user.langs;

console.log(`${html} ${css} ${js}`);