What is this type of variable assignment called: const {a, b, c} = x;?

Viewed 233

The type of assignment I want to learn about probably has lots of explanations online, but I can't find them because I don't know what it's called. So what do you call this form of variable assignment in Javascript const {a, b, c} = x;?

1 Answers

It is called destructuring assignment.

It takes an object as value and variables, where the names reflects the same named properties and assigns the value to it.

const x = { a: 1, b: 2, c: 3, d: 4 };
const { a, b, c } = x;

console.log(a, b, c);

Related