I haven't seen anything here or on MDN. I'm sure I'm just missing something. There's got to be some documentation on this somewhere?
Functionally, it looks like it allows you to nest a variable inside a string without doing concatenation using the +
operator. I'm looking for documentation on this feature.
Example:
var string = 'this is a string';_x000D_
_x000D_
console.log(`Insert a string here: ${string}`);
_x000D_
This question is related to
javascript
string
variables
concatenation
You're talking about template literals.
They allow for both multiline strings and string interpolation.
Multiline strings:
console.log(`foo_x000D_
bar`);_x000D_
// foo_x000D_
// bar
_x000D_
String interpolation:
var foo = 'bar';_x000D_
console.log(`Let's meet at the ${foo}`);_x000D_
// Let's meet at the bar
_x000D_
As mentioned in a comment above, you can have expressions within the template strings/literals. Example:
const one = 1;_x000D_
const two = 2;_x000D_
const result = `One add two is ${one + two}`;_x000D_
console.log(result); // output: One add two is 3
_x000D_
You can also perform Implicit Type Conversions with template literals. Example:
let fruits = ["mango","orange","pineapple","papaya"];
console.log(`My favourite fruits are ${fruits}`);
// My favourite fruits are mango,orange,pineapple,papaya
Source: Stackoverflow.com