Fonksiyon Parametre Nesnelerinin Yapısını Bozma JavaScript'te
Benzer şekilde, parametre nesnelerinin yapısı bozulabilir:
function func({year, month, day}) {
console.log(year); // 2025 yazacak
console.log(month); // 12 yazacak
console.log(day); // 31 yazacak
}
func({year: 2025, month: 12, day: 31,});
Aşağıdaki kodu öğrenilen teoriye göre yapıyı bozarak değiştirin:
function func(options) {
let color = options.color;
let width = options.width;
let height = options.height;
}
func( {color: 'red', width: 400, height: 500} );
Aşağıdaki kodu öğrenilen teoriye göre yapıyı bozarak değiştirin:
function 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} );