2.4.2 문자열 치환
템플릿 리터럴은 문자열의 일부를 특정 값으로 치환할 수 있는 수단을 제공한다.
const name = 'Ahn Heejong';
function greetingsWithConcat(name) {
console.log('Hello, ' + name + '!');
}
function greetingsWithArrayJoin(name) {
const greetings = ['Hello, ', name, '!'];
console.log(greetings.join(''));
}function beforeES6(firstName, lastName) {
console.log('My name is ' + firstName + ' ' + lastName +'!');
}
function sinceES6(firstName, lastName) {
console.log(`My name is ${firstName} ${lastName}!`);
}
beforeES6('Heejong', 'Ahn'); // My name is Heejong Ahn!
sinceES6('Heejong', 'Ahn'); // My name is Heejong Ahn!Last updated