Skip to content

Template Strings

String literals can only be used to denote a fixed string. Sometimes, however, parts of the string have to be computed and then interpolated into the remaining text. This is done with template strings. Here is an example:

`1 + 2 = { 1 + 2 }`

Template strings are also delimited by backticks, the text can contain escape sequences, and raw newlines can be inserted. The additional syntax are template expressions, which are any expression enclosed by { and }.

These template expressions are evaluated, converted to a string and inserted into the template string at their position. The template string in the example above is, hence, equivalent to the string literal "1 + 2 = 3".