javascript multiline strings in the code [ 705 views ]
Goal: use multiline strings in the code
I have a simple string template. I want to store it in a variable but I want to forget the concatenation.
We can use the following trick.
var itemTemplate = `<li>
<div class="direction-r">
<div class="flag-wrapper">
<span class ="flag">${0}</span>
<span class ="time-wrapper">${1}</span>
</div>
<div class ="desc">${2}</div>
</div>
</li>`;
console.log(itemTemplate);
the trick is the GRAVE ACCENT character -> `
see also: GRAVE ACCENT