Template Strings in Javascript ES6

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

To show you template string in Javascript ES6, we continue directly from last tutorial but with one line changed…

template string

The result is the same.  Instead of using the single of double quotes to mark the start and end of a string, we use the back-tick.  This enables us to use interpolation variables inside the string denoted by dollar sign and curly braces as we did for ${name} and ${sum}.

In fact, you can even put some simple Javascript operations or method calls inside the curly braces as in here where we called toUpperCase() method…

template string in multiline

And look, the template string can be broken into multiple lines — here it spans three lines.  You could not do this with regular strings.

More ES6 features here.