Variablat dhe Vlerat e Parazgjedhura në JavaScript
Gjithashtu mund të ndryshoni emrat e variablave sipas dëshirës duke caktuar vlera të parazgjedhura:
let obj = {
month: 12,
day: 31,
};
let {year:y = 2025, month, day} = obj;
console.log(y); // shfaq 2025
console.log(month); // shfaq 1
console.log(day); // shfaq 31
Në kodin vijues pjesët e objektit shkruhen në variablat përkatëse:
let options = {
width: 400,
height: 500,
};
let c;
if (options.c !== undefined) {
c = options.color;
} else {
c = 'black';
}
let w = options.width;
let h = options.height;
Rishkruajeni këtë kod përmes destabilizimit sipas teorisë së mësuar.