The Handsome Template Literals

Michele Riva
openmind
Published in
3 min readMar 3, 2019

--

What if we need to concatenate some strings?
ES5 forces us to approach the problem in the following way:

Such an ugly way to concatenate strings!
Thankfully, with ES6 JavaScript introduces Template Literals, which will help us to concatenate strings as follows:

The greatest part of template literals, is that you can write any kind of JavaScript expression inside a string.
Let me explain that with the following code:

We just made some math inside a string!

Why should we care about writing some expressions inside a string?

Because sometimes it can make things easier. We can call functions, doing maths and other kind of stuff without writing extra boilerplate code.

--

--