0 day streak
javascript / beginner
Snippet

Template Literals for Dynamic Strings

Template literals use backticks (`) instead of quotes. They allow you to embed variables directly into strings using the ${variable} syntax.

snippet.js
javascript
1
2
3
4
5
function Profile() {
const name = 'Alex';
const bio = `User: ${name}`;
return <div>{bio}</div>;
}
react
Breakdown
1
const bio = `User: ${name}`;
Uses backticks and ${} to insert the variable 'name' into the string.