Theme
Primary Color
Lesson 18

Destructuring Function Parameters

محتوى الدرس

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

// First Example

const user = {
  username: 'Osama',
  city: 'Cairo',
  skills: {
    html: '80%',
    css: '85%',
    js: ['Vuejs', 'Reactjs', 'Angularjs']
  }
};

// const {username, city, skills: {html, css, js: [one, two, three]}} = user;

function showMyInfo(user) {
  console.log(`My Name Is ${user.username}, And I Live in ${user.city}.`);
  console.log(`My Html Skill Progress Is: ${user.skills.html}, and CSS is ${user.skills.css}`);
  console.log(`I Have Knowledge in Js Frameworks Like ${user.skills.js[0]}, ${user.skills.js[1]}, ${user.skills.js[2]}`);
}

showMyInfo(user);

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

// Second Example

const user = {
  username: 'Osama',
  city: 'Cairo',
  skills: {
    html: '80%',
    css: '85%',
    js: ['Vuejs', 'Reactjs', 'Angularjs']
  }
};

// const {username, city, skills: {html, css, js: [one, two, three]}} = user;

function showMyInfo({username, city, skills: {html, css, js: [one, two, three]}}) {
  console.log(`My Name Is ${username}, And I Live in ${city}.`);
  console.log(`My Html Skill Progress Is: ${html}, and CSS is ${css}`);
  console.log(`I Have Knowledge in Js Frameworks Like ${one}, ${two}, ${three}`);
}

showMyInfo(user);