Template Literals

Template literals are very similar to string literals, but they use backticks (`) instead of single quotes (') or double quotes (").

Basic

Multi-line

Fruits

Vegetables

Interpolation

Template literals get their name from their ability to evaluate expressions. Think of a form letter template with blanks to hold names or numbers that can be filled in later: "Dear ______, Thank you for your business on ______! Sincerely, Management" Similarly, values can be filled, or interpolated, into template literals, to be evaluated when the program runs.

Forgetting to include spaces is a common mistake that is made with concatenating strings together. Using template literals and placeholders instead makes it less cluttered and mistakes easier to see.

You can pass any kind of expression, even a function expression, into these curly brackets.