JavaScript `...${}` Template literal Operator
Template literals are strings written in backticks that can span several lines and include values with ${expression}.
Description
A template literal is a string written with backticks. Expressions inside ${...} are evaluated and inserted (interpolation), and the string can span multiple lines without escape characters. It's usually clearer than joining strings with +.
A function name placed before the backtick creates a tagged template: the function receives the string parts and the values separately and can return anything. String.raw is a built-in tag, and libraries use tags for things like safely escaping HTML or defining CSS. Inserting user input into HTML with a template literal doesn't escape it, so take care to avoid cross-site scripting.
To include a literal backtick in a template, escape it with a backslash, and to include a literal ${, escape the dollar sign: \${. Any expression can go inside the placeholders, including function calls, ternaries and other template literals, and the result is converted to a string. Leading indentation on later lines is part of the string, which matters when building multi-line text.
Properties
- Operator
`...${}`- Category
- Other
- Precedence
- n/a
- Associativity
- n/a
Syntax
`text`
`text ${expression} text`
tag`text ${expression}`Example
Browser Support
The following information will show you the current browser support for the `...${}` operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





