javascript / beginner
Snippet
Template Literals for Dynamic Strings
Template literals allow you to embed variables and expressions directly into strings using backticks and the ${} syntax, which is cleaner than string concatenation.
snippet.js
1
2
3
const WelcomeMessage = (props) => {return <h1>{`Welcome back, ${props.user}!`}</h1>;};
react
Breakdown
1
`Welcome back, ${props.user}!`
The backticks define a template literal, and ${} injects the value of props.user into the string.