Template Literals
In traditional JavaScript, text that is enclosed within matching "
marks, or '
marks is considered a string. Text within double or single quotes can only be on one line. There was also no way to insert data into these strings. This resulted in a lot of ugly concatenation code that looked like:
ES6 introduces a new type of string literal that is marked with back ticks (`). These string literals can include newlines, and there is a new mechanism for inserting variables into strings:
The ${}
works fine with any kind of expression, including member expressions and method calls.
There are all sorts of places where these kind of strings can come in handy, and front end web development is one of them.
Further reading
Last updated
Was this helpful?