الرجوع الي الدرس
هذة المادة العلميه متاحه فقط باللغات الأتيه: English, Español, Français, Indonesia, Italiano, 日本語, 한국어, Русский, Türkçe, 简体中文. من فضلك, ساعدنا قم بالترجمه إلى عربي.

Destructuring assignment

الأهمية: 5

We have an object:

let user = {
  name: "John",
  years: 30
};

Write the destructuring assignment that reads:

  • name property into the variable name.
  • years property into the variable age.
  • isAdmin property into the variable isAdmin (false, if no such property)

Here’s an example of the values after your assignment:

let user = { name: "John", years: 30 };

// your code to the left side:
// ... = user

alert( name ); // John
alert( age ); // 30
alert( isAdmin ); // false
let user = {
  name: "John",
  years: 30
};

let {name, years: age, isAdmin = false} = user;

alert( name ); // John
alert( age ); // 30
alert( isAdmin ); // false