Template Literals
👨💼 Template literals are a powerful way to work with strings in JavaScript.
Instead of using quotes (
' or "), you use backticks (`).The magic of template literals is string interpolation - you can embed
variables and expressions directly inside the string using
${...}:const name = 'Alice'
const greeting = `Hello, ${name}!`
// "Hello, Alice!"
You can also create multi-line strings without any special characters:
const poem = `Roses are red,
Violets are blue,
JavaScript is awesome,
And so are you!`
- Create variables for
firstNameandlastName - Create a
fullNameusing a template literal that combines them - Create an
agevariable with a number - Create a
biothat includes the name and age using interpolation - Create a multi-line
addressstring - Log all of them to see the results
💰 You can put any expression inside
${...}:console.log(`2 + 2 = ${2 + 2}`) // "2 + 2 = 4"