템플릿 리터럴 Template literals

양주영·2021년 10월 1일
0

javascript

목록 보기
28/42

템플릿 리터럴은 내장된 표현식을 허용하는 문자열 리터럴이다.
이는 이중 따옴표나 작은 따옴표 대신 백틱(``)${}를 사용해서 문자열과 변수를 적절히 같이 사용 가능하다.

let num1 = 10;
let num2 = 20;
let result = 30;
let string1 = num1 +"더하기" + num2 + "는 " + result + "";
console.log(string1); //10 더하기 20은 '30'

위의 코드는 아래와 같이 작성할 수 있다.

let num1 = 10;
const num2 = 20;

console.log(`${num1} + ${num2} = ${num1 + num2}입니다.`); // 10+20 = 30입니다.


참고 >
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals

profile
뚜벅뚜벅

0개의 댓글