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"
μ°Έκ³ μλ£
β Symbol Global Object β