티스토리 뷰
템플릿리터럴(template literal)
템플릿리터럴 사용하면 뭐가 좋을까?
- 특정 문자열이 담긴 변수를 동적으로 사용할 수 있게된다.
- str1 + srt2 와 같이 문자열을 연결할 때 보다 가독성이 좋다.
사용방법
문자열 안에 변수를 사용하기 위해서는 백틱(`)으로 문자열을 감싸고 ${} 구문을 사용하여 변수를 삽입한다.
const apple = "Iphone";
const samsung = "Galaxy";
function templateTest (someString) {
const variable = `${someString} is the best!`
console.log(variable)
return variable
}
const result1 = templateTest(apple);
const result2 = templateTest(samsung);
'개발공부 > Javascript' 카테고리의 다른 글
#기본기8_객체에서 속성을 추가하거나 삭제하는 방법 (0) | 2024.04.03 |
---|---|
#기본기7_배열에서 특정요소를 찾기 (1) | 2024.04.03 |
#기본기5_비교연산자 (==와 ===, null과 undefined) (0) | 2024.04.02 |
#기본기4_문자열과 숫자의 결합 (0) | 2024.04.02 |
#기본기3_var, let, const의 차이 (0) | 2024.04.02 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 함수
- 함수형코딩
- JSX
- Props
- null과 undefined
- 상속
- 태스크큐
- 머리아프다..
- .catch()
- .finally()
- 프로토타입 체이닝
- unexpected character
- 미들웨어위치
- universal rendering
- 전역변수
- 문자열
- react
- 에이블스쿨2일차
- 배열내특정요소찾기
- .then()
- 객체리터럴
- 객체속성 추가 삭제
- 리액트 이미지경로
- 동등비교연산자
- promise
- cors위치
- 조대곤교수님
- unique "key" prop.
- 비동기
- 대괄호표기법
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함