Extra values during destructuring an array in JavaScript
If the array has less elements than variables,
then undefined will be written into
the "extra" variables:
let arr = [2025, 12];
let [year, month, day] = arr;
console.log(year); // shows 2025
console.log(month); // shows 12
console.log(day); // shows undefined
If there are more elements in the array than variables, the extra elements will not be written anywhere and nothing bad will happen. For example, let's add hours, minutes and seconds to our array - nothing will change from this:
let arr = [2025, 12, 31, 23, 59, 59];
let [year, month, day] = arr;
console.log(year); // shows 2025
console.log(month); // shows 12
console.log(day); // shows 31