Destructuring is a [[programming language]] feature, usually a kind of [[syntactic sugar]], where local variables are assigned to the values of an inner objects values.
Consider [[JavaScript]]:
In JavaScript, consider the following object assigned to the variable x:
const x = {
a: 1,
b: 'foo'
};
In many programming languages, JavaScript included, itโs conventional to assign variables to inner fields when working with those fields.
const x = {
a: 1,
b: 'foo'
};
const a = x.a;
const b = x.b;
console.log('a', a, 'b', b);
Many languages therefore offer a shortcut, called destructuring. The following JavaScript is equivalent to the prior block:
const x = {
a: 1,
b: 'foo'
};
const {a, b} = x;
console.log('a', a, 'b', b);