Template Strings
Unlike normal strings, template strings are enclosed in back-ticks ``
.
let message = `hello world`;
Single and Double Quotes
With template strings, we can use single and double quotes inside a string without escaping.
let message = `hello "world"`;
let message = `hello 'world'`;
Multiline Strings
With template strings we can define multiline stings without using a new line escape character \n
inside the string.
let message = `hello world
welcome to new world
learn javascript here`;
Variables inside String
Template strings allow interpolation of variables or expressions inside a string.
The syntax to interpolate a variable inside a template string is
${variable}
The following is an example to include a variable in a template string
let name = 'Arjun';
console.log(`Hello ${name}`);
let a = 4;
let b = 8;
console.log(`${a} + ${b} = ${a + b}`);