let chosen = 4;
let team = [
{ titel: "ahmad", age: 20, available: true, skills: ["html", "css"] },
{ titel: "mizo", age: 30, available: false, skills: ["js", "react"] },
{ titel: "jo", age: 40, available: true, skills: ["pyhton", "django"] },
];
(() => {
if (chosen === chosen) {
let {
titel,
age,
available,
skills: [s1, s2],
} = team[chosen - 1];
console.log(`Team-${chosen}:
name: ${titel}
age: ${age}
skill: ${s1}
availability: ${(() => {
if (available) return `available`;
else return `unavailable`;
})()}
`);
} else return;
})();
why the given code above throws this error (Uncaught TypeError: Cannot destructure property 'titel' of 'team[(chosen - 1)]' as it is undefined.) in the console if you choose a number less than 1 or greater than 4 ??