Re:Why Does “=” Mean Assignment?
by OvermindDL1 on Wednesday April 11, 2018 @10:28AM
(#16811394)
Javascript itself supports destructuing fine, here's some javascript straight from the firefox console:
> let a = [1,2,3]
undefined
> [x,y,z] = a
Array(3) [ 1, 2, 3 ]
> x
1
> y
2
> z
3
Basically it means that you can assign several variables at once, by asssigning a complex value to an aproprietly structured literal with variables as placeholders.
In pseudojavascript, let's say you got this from some API:
And you want to extract useful data for your code quickly. In languages with destructuring you can do sth like this: And the language will put the correct values in your variables name, age, firstCarId, firstCarModl, restOfTheCars.