ফাংশন প্যারামিটার হিসেবে অবজেক্ট ডেস্ট্রাকচারিং ইন জাভাস্ক্রিপ্ট

একইভাবে অবজেক্ট প্যারামিটারগুলিকে ডেস্ট্রাকচার করা যেতে পারে:

javascriptfunction func({year, month, day}) {
  console.log(year);  // 2025 প্রিন্ট করবে
  console.log(month); // 12 প্রিন্ট করবে
  console.log(day);   // 31 প্রিন্ট করবে
}

func({year: 2025, month: 12, day: 31,});
Задание 1

নিম্নলিখিত কোডটি শেখা তত্ত্ব অনুযায়ী ডেস্ট্রাকচারিং এর মাধ্যমে পুনরায় লিখুন:

javascriptfunction func(options) {
  let color  = options.color;
  let width  = options.width;
  let height = options.height;
}

func( {color: 'red', width: 400, height: 500} );
Задание 2

নিম্নলিখিত কোডটি শেখা তত্ত্ব অনুযায়ী ডেস্ট্রাকচারিং এর মাধ্যমে পুনরায় লিখুন:

javascriptfunction func(options) {
  let width  = options.width;
  let height = options.height;
  
  let color;
  if (options.color !== undefined) {
    color = options.color;
  } else {
    color = 'black';
  }
}

func( {color: 'red', width: 400, height: 500} );