← All references

Template Literals

`text ${expression}`

String interpolation with backticks.

Template Literals

Use backticks ( ) to create strings with embedded expressions.

``js\nconst name = "Aarav";\nconst greeting = Hello, ${name}!;\n// "Hello, Aarav!"\n\nconst sum = ${1 + 2}; // "3"\nconst multi = \nLine 1\nLine 2\n; // multi-line\n``

Example

const name = "Priya";\nconst age = 21;\nconsole.log(`Hello, ${name}!`);\nconsole.log(`Next year you'll be ${age + 1}`);\n\nconst a = 5, b = 3;\nconsole.log(`${a} + ${b} = ${a + b}`);