February 2018
Intermediate to advanced
298 pages
8h 22m
English
Template strings provide a new way to create strings that contain multiple lines of text. In ES5, we need to use the \n newline character to add new line breaks. Here is an example to demonstrate this:
console.log("1\n2\n3");
The output is as follows:
123
In ES6, using a multiline string, we can simply write:
console.log(`123`);
The output is as follows:
123
In the preceding code, we simply included new lines where we needed to place \n. While converting the template string to the normal string, the new lines are converted to \n.
Read now
Unlock full access