What are template literals in JavaScript?
const name = "Robin";
const age = 25;
console.log(`Name: ${name}, age next year: ${age + 1}`);
console.log(`Line 1
Line 2`);
Output:
Tutorials Class - Output Window
Name: Robin, age next year: 26
Line 1
Line 2
Backticks give string interpolation with ${ } and allow multi-line strings. See JavaScript Strings.
Learn more about the similar topics:
| Tutorials |
|---|
| JavaScript Strings |
| JavaScript Regular Expressions |
| Exercises & Assignments |
|---|
| Write a JavaScript program to reverse a string |
| Write a JavaScript program to check palindrome string |
| Write a JavaScript program to count vowels in a string |
| Interview Questions & Answers |
|---|
| What are template literals in JavaScript? |