What does ${} (dollar sign and curly braces) mean in a string in Javascript?

Darren Joy picture Darren Joy · Mar 7, 2016 · Viewed 157.7k times · Source

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:

Answer

Rick Runyon picture Rick Runyon · Mar 7, 2016

You're talking about template literals.

They allow for both multiline strings and string interpolation.

Multiline strings:

console.log(`foo
bar`);
// foo
// bar

String interpolation:

var foo = 'bar';
console.log(`Let's meet at the ${foo}`);
// Let's meet at the bar