javascript / beginner
Snippet
Dynamic Strings with Template Literals
Template literals allow you to embed variables directly into strings using backticks and the ${} syntax. This makes string concatenation much cleaner and easier to read.
snippet.js
1
2
3
4
export default function Welcome({ name }) {const message = `Welcome back, ${name}!`;return <h1>{message}</h1>;}
nextjs
Breakdown
1
const message = `...`
Uses backticks instead of quotes to define a string that supports interpolation.
2
${name}
Placeholder that inserts the value of the name variable into the string.