Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;?

like image 441
achalk Avatar asked Oct 30 '25 16:10

achalk


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);
like image 68
Nina Scholz Avatar answered Nov 02 '25 07:11

Nina Scholz