0

In javascript you can do things like:

const person = {name: 'Tom', surname: 'Smith'};
const { name } = person

and then you will have name equal to 'Tom'.

The question is - how is this "operation" of taking name from person and storing it as variable called?

pbialy
  • 799
  • 9
  • 20
  • 1
    It's "destructuring," in that case "destructuring assignment." From [*de-*](https://www.merriam-webster.com/dictionary/de-) (*remove from*) and [*structure*](https://www.merriam-webster.com/dictionary/structure) (*organization of parts as dominated by the general character of the whole*). The *de-* part is *slightly* a misnomer, it doesn't *remove* `name` from `person`, it just extracts it. But the terminology was well-established long before JavaScript. There's also parameter value destructuring and argument destrcuturing (same thing, different contexts). – T.J. Crowder Aug 13 '20 at 10:32

1 Answers1

1

This is called destructuring assignment. Please refer to MDN web docs

Julian Kleine
  • 1,251
  • 4
  • 13