capypad
0 day streak
javascript / beginner
Snippet

Working with Template Literals

Template literals (using backticks ``) allow you to easily embed variables inside strings using the ${variable} syntax, making code much cleaner than using the + operator.

snippet.js
javascript
1
2
3
const user = "Alice";
const greeting = `Hello, ${user}!`;
console.log(greeting);
Breakdown
1
const user = "Alice";
Stores a string value in a constant.
2
`${user}`
The ${} syntax inserts the value of the variable directly into the string.