About Object Destructuring

Just a couple questions, but does the names of the variables to hold the properties of the object being destructed have to be consistent with the property names?

Also, does the order in which the variables are declared in the syntax matter when destructing the object?

An example:

const storeLocation = {
  addressNumber: 9010
  streetName: JinxFade
  streetAbbrev: Dr.
  city: Mabeline
  state: JS
  zipcode: 12201
} 

const { addressNumber, streetName } = storeLocation; //<-This is fine.
const { zipcode, cityName } = storeLocation; /*<-Will this work? 

Even if there is no property with the name "cityName"?
Also, since zipcode comes in third in overall order, does it receive the streetAbbrev value instead?
*/

Hi @CasualWanderer20XX

The object does not have correct syntax.
Strings require quote marks, and a comma is required to separate each key/value pair.

As far as I know, the variable names needs to match the property in the object. So the order of the variable does not matter. For arrays, you can use any valid variable name you like.

Try placing your code in a fCC editor and console log the variable.

Happy coding

const { zipcode: zip, cityName: myCity } = storeLocation;

you can use whatever variable name you want with the extended syntax

thus will give variables zip and myCity