Template strings in JavaScript

There is a special type of quotes - backticks:

let str = `abc`; alert(str); // shows 'abc'

With backticks you can perform insertion of variables. To do this, you need to write the variable name in the construction ${}.

Let's look at an example. Let's say we want to add strings and a variable:

let str = 'xxx'; let txt = 'aaa ' + str + ' bbb';

This code can be rewritten like this:

let str = 'xxx'; let txt = `aaa ${str} bbb`;

Rewrite the following code, using variable insertion:

let str1 = 'xxx'; let str2 = 'yyy'; let txt = 'aaa ' + str1 + ' bbb ' + str2 + ' ccc';

Multiline strings

In JavaScript, strings created with single or double quotes do not allow line wrapping. It means, the following won't work:

let str = 'abc def'; // that won't work

This also won't work:

let str = "abc def"; // that won't work

But the backticks are especially designed to create multiline strings:

let str = `abc def`; // this will work

Write the string, consisting of characters 'a', 'b', 'c', to the variable str. There should be a line wrapping after each character, except the last one.

enru