Example 1 — Expressions inside
Any expression works.
JavaScript
console.log(`2+3=${2 + 3}`);How It Works
- The expression is evaluated, then stringified.
Template literals use backticks (`). Embed expressions with ${...}. They may span multiple lines without \n escapes.
const name = "Ada";
console.log(`Hello, ${name}!`);
console.log(`line1
line2`);Any expression works.
console.log(`2+3=${2 + 3}`);Possible but keep readable.
const x = 1;
console.log(`value=${`<${x}>`}`);Raw escapes.
console.log(String.raw`C:\new`);CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful