Just using the new ES6 backticks to:
- Display multiline text.
- Embed variable values into strings (similar to print.format or c# string.format).
- Let's first create a multiline text using an ES6 approach:
const myString = 'This is a try to get a long string in several lines' +
'using classic ES5 approach';
console.log(myString);
This approach sucks: is prone to errors.
- Now let's do the same using backticks:
const myString = `This is a try to get a long string in several lines
using classic ES6 backticks`;
console.log(myString);
- What if we want to display the value of a variable? we can use ${}
const percentage = 80;
const myString = `Total sales increase: ${percentage} %`;
console.log(myString);