**destructuring(디스트럭처링)**이란? 배열의 각 요소를 배열로부터 추출하여 변수 리스트에 할당하는 것 이다.

(추출/할당 기준은 배열의 인덱스이다)

function address_maker(city, state) {
  const new_address = { city: city, state: state }; // const new_address = {city,state}으로도 사용가능
  console.log(new_address); // city: "ame", state:"japan"
}
address_maker("ame", "japan");

함수 안에 new_address라는 object가 있고 그 object 안에 ame와 japan이라는 매개변수를 바다 value로 등록하고 console log로 출력한다.

문제

destructuring을 최대한 사용해서 다음 코드를 바꿔보자

//1.첫번째 방법
function addressMaker2(address){
  const newAddress2 = {
    city: address.city,
    state: address.state,
    country: 'United States',
  }
  const {city, state, country} = newAddress2
  console.log(city, state, country)
}
addressMaker2({city: 'Austin', state: 'Texaxs'})
//2.첫번째 방법
function addressMaker(address) {
  const { city, state } = address;
  const newAddress = {
    city,
    state,
    country: "United States"
  };
  console.log(newAddress.city, newAddress.state, newAddress.country);
}
addressMaker({ city: "Austin", state: "Texaxs" });