내일배움캠프 동영상 강의/내배캠_ React 입문

template literals 와 destructuring

콛 다이어리 2024. 8. 9. 01:12

Template Literals
변수와 표현식을 

문자열 안에 쉽게 삽입할 게 해주는 문법


백틱(`)
문자열을 여러 줄로 작성하는 목적으로도 사용됨


const customer = {
name: "인스피릿",
   };
const item = {
name: 스타크래프트 리마스터 카툰팩";
price: 50,
};
console.log("감사합니다. " + customer.name + "님!"); 

// 감사합니다. 인스피릿님!
console.log("감사합니다. " + customer.name + "님!" +
 item.name + "을(를) +
 item.price + "원에 구매하셨습니다.");
// 감사합니다. 인스피릿님! 스타크래프트 리마스터 카툰팩을 50원에 구매하셨습니다.

console.log(`감사합니다. $(customer.name}님!`);
const orderDetails2 =

 `

고객 : ${customer.name}
상품 : ${item.name}
가격 : ${item.price}
`;
// 감사합니다. 인스피릿님! 스타크래프트 리마스터 카툰팩을 50원에 구매하셨습니다.

 


destructuring (de: not의 의미/ structuring: 구조)

순서가 중요

배열은 index가 key를 대신


const today = {
weather: "여름",
temperature: 33,
};
얘는
const diaryWriting1 = today.weather;
const diaryWriting2 = today.temperature


// 속성이 몇억 몇천개면 다 하나씩 입력해야 함
// 그걸 대신 해주는 게 destructuring
const { weather, temperature } = item;

const = ["red", "green", "blue"];
const [firstColor, secondColor] = colors;


console.log(firstColor); 

// red
console.log(secondColor); 

// green
// 인덱스 위치만 맞으면 됨
// blue가 필요하면
console.log(, , thirdColor);

'내일배움캠프 동영상 강의 > 내배캠_ React 입문' 카테고리의 다른 글

DOM  (0) 2024.08.17
화살표 함수, 조건연산자, 단축평가  (0) 2024.08.09
promise, async, await  (0) 2024.08.09
모듈  (0) 2024.08.09
template literals, spread와 rest  (0) 2024.08.09