It is not necessary to declare variables when destructuring. They may be declared in advance:
let obj = {
year: 2025,
month: 12,
day: 31,
};
let year, month, day; // declares variables in advance
Here, however, unlike arrays, there are
nuances. Without the let
command
before the curly braces, these curly
braces will not be interpreted by
JavaScript as a destructuring command
(but will be perceived as a block of code):
{year, month, day} = obj; // will not work
To solve the problem, the command to destruct the object must be taken in parentheses:
({year, month, day} = obj);