Template Literals

λ‚΄μž₯된 ν‘œν˜„μ‹μ„ ν—ˆμš©ν•˜λŠ” λ¬Έμžμ—΄ λ¦¬ν„°λŸ΄ 이닀.
λ°±ν‹± ( ' : backtick) 을 μ΄μš©ν•œ 방식이닀.

const template = `ν…œν”Œλ¦Ώ λ¦¬ν„°λŸ΄μ€ 'μž‘μ€λ”°μ˜΄ν‘œ(single quotes)'κ³Ό "ν°λ”°μ˜΄ν‘œ(double quotes)"λ₯Ό ν˜Όμš©ν•  수 μžˆλ‹€.`;

console.log(template);
const template = `<ul class="nav-items">
  <li><a href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>`;

console.log(template);

ν…œν”Œλ¦Ώ λ¦¬ν„°λŸ΄μ€ + μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šμ•„λ„ κ°„λ‹¨ν•œ λ°©λ²•μœΌλ‘œ μƒˆλ‘œμš΄ λ¬Έμžμ—΄μ„ μ‚½μž…ν•  수 μžˆλŠ” κΈ°λŠ₯을 μ œκ³΅ν•œλ‹€. 이λ₯Ό λ¬Έμžμ—΄ μΈν„°ν΄λ ˆμ΄μ…˜(String Interpolation)이라 ν•œλ‹€.

const first = 'Ung-mo';
const last = 'Lee';

// ES5: λ¬Έμžμ—΄ μ—°κ²°
console.log('My name is ' + first + ' ' + last + '.');
// "My name is Ung-mo Lee."

// ES6: String Interpolation
console.log(`My name is ${first} ${last}.`);
// "My name is Ung-mo Lee."

λ¬Έμžμ—΄ μΈν„°ν΄λ ˆμ΄μ…˜μ€ ${ … } 으둜 ν‘œν˜„μ‹μ„ 감싼닀. λ¬Έμžμ—΄ μΈν„°ν΄λ ˆμ΄μ…˜ λ‚΄μ˜ ν‘œν˜„μ‹μ€ λ¬Έμžμ—΄λ‘œ κ°•μ œ νƒ€μž… λ³€ν™˜λœλ‹€.

console.log(`1 + 1 = ${1 + 1}`);
// "1 + 1 = 2"