javascript / beginner
Snippet
Template Literals for Dynamic Strings
Template literals use backticks (`) instead of quotes. They allow you to insert variables directly into a string using the ${variable} syntax.
snippet.js
1
2
3
const user = "Alice";const greeting = `Hello, ${user}!`;console.log(greeting);
nodejs
Breakdown
1
const user = "Alice";
Creates a constant string variable.
2
const greeting = `Hello, ${user}!`;
Uses backticks and ${} to embed the variable into the string.
3
console.log(greeting);
Prints the final string to the console.