// before ES6 const introduceMyBearInES5 = 'My favorite bear is '+ myFavorite + ', and his tommy smells like'+ flavour +'.'; // ES6 const introduceMyBearInES6 = `My favorite bear is ${myFavorite}, and his tommy smells like ${flavour}.`;
const introducePresident = `Our President is ${getFullName(President)}. He is ${President.height > 80 ? 'tall' : 'short'}. ` // 'Our President is Lotso Bear. // He is short.'
/* 呼叫 printSomething, 並將模版字符串作為引數代入 */ printSomething(`My favorite bear is ${myFavorite}.`) // 'My favorite bear is Lotso.'
/* call printSomething as a tagged template literal(標籤樣板字面值)*/ printSomething`My favorite bear is ${myFavorite}.` //["My favorite bear is ", "."], "Lotso"
printSomething`My favorite bear is ${myFavorite}, and his tommy smells like ${flavour}.`; /** * ["My favorite bear is ", ", and his tommy smells like ", "."] * "Lotso" * "strawberries" **/
printSomething(`My favorite bear is ${myFavorite}, and his tommy smells like ${flavour}.`) // "My favorite bear is Lotso, and his tommy smells like strawberries."
printSomething`My favorite bear is ${myFavorite}, and his tommy smells like ${flavour}.`; /** * ["My favorite bear is ", ", and his tommy smells like ", "."] * "Lotso" * "strawberries" **/