Web Technologies - JAVASCRIPT

Back to Course

Lesson Description

Lession - #214 Javascript String Templates

Templates literals are literals delimited with backticks ('>
, permitting embedded expressions called substitutions.

Untagged templates literals result in strings, which makes them useful for string introduction (and multiline strings, since unescaped newlines are permitted>

Template literals are call a function (the tag function>
with a array of any text segments from the literal followed by arguments with the values of any replacements, which is helpful for DSLs.

Template literals are some of the time called template strings, yet they aren't string literals and can't be utilized wherever a string literal can be utilized. Additionally, a tagged template literal may not result string; it's up to the tag function what it creates (if anything>

Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}>
. The expressions in the placeholders and the text between the backticks (' '>
get passed to a function.


Let's see an example

<!DOCTYPE html>

<h2>JavaScript Template Literals</h2>

<p>Template literals use back-ticks (``>
to define a string:</p> <p id="demo"></p> <p>Template literals are not supported in Internet Explorer.</p> <script> let text = `Teched Solution`; document.getElementById("demo">
.innerHTML = text; </script> </body> </html>


Try it here