7.8. Template Literals¶
/*Template literals allow for the automatic insertion of expressions
(including variables) into strings.
While normal strings are enclosed in single or double quotes
(' or "), template literals are enclosed in back-tick characters,
`. Within a template literal, any expression surrounded by ${ }
will be evaluated, with the resulting value included in the string.
Template literals allow for variables and other expressions to be
directly included in strings.*/
let name = "Jack";
let currentAge = 9;
console.log(`Next year, ${name} will be ${currentAge + 1}.`);
//Next year, Jack will be 10.
//Example2:
let poem = `The mind chases happiness.
The heart creates happiness.
The soul is happiness
And it spreads happiness
All-where.
– Sri Chinmoy`;
console.log(poem);
/*The mind chases happiness.
The heart creates happiness.
The soul is happiness
And it spreads happiness
All-where.
– Sri Chinmoy