Since ES6, you can use template literals:

const age = 3
console.log(`I'm ${age} years old!`)

P.S. Note the use of backticks: ``.

Answer from Damjan Pavlica on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Template_literals
Template literals (Template strings) - JavaScript | MDN
Along with having normal strings, template literals can also contain other parts called placeholders, which are embedded expressions delimited by a dollar sign and curly braces: ${expression}. The strings and placeholders get passed to a function — either a default function, or a function you supply. The default function (when you don't supply your own) just performs string interpolation to do substitution of the placeholders and then concatenate the parts into a single string.
Discussions

TIL JavaScript provides string interpolation with string template literals
Next thing to learn is probably tagged templates I have never really used them outside of React styled-components so you probably won't see them much but it's good to know they exist More on reddit.com
🌐 r/ProgrammerTIL
3
10
October 2, 2023
JavaScript : Can I use string interpolation to create dynamic variable names?
Sure you can. Just use eval. Disclaimer: if you ever write eval in any codebase I have control over for this purpose, I will burn down your house. More on reddit.com
🌐 r/AskProgramming
12
2
December 21, 2021
How to convert a string literal to string interpolation?
The only kind of interpolation JS supports out of the box is through template literals which happens when the string is parsed within the source code. If you have arbitrary input as a string, there's nothing built-in that will automatically go through that string and swap out template tags with their respective values like what you get with template literals. However, for basic usage you can easily do something similar with a regex replace. const input = "

Hello {username}

" const params = { username: "marvelhoax" } const output = input.replace(/{(.*?)}/g, (match, param) => param in params ? params[param] : match) console.log(output) //

Hello marvelhoax

More on reddit.com
🌐 r/learnjavascript
7
1
January 17, 2023
I made a new string interpolation library (typed-string-interpolation)
Can understand the efforts to push for lower bundle size but I glanced at your code and the variable names are single letters :| Is this by design? More on reddit.com
🌐 r/typescript
7
9
June 28, 2023
🌐
Hng
hng.tech › learn › learn-javascript-programming-online-with-step-by-step-video-tutorials › string-interpolation-with-template-literals
String Interpolation with Template Literals | HNG Learn
Multi-Line Strings: Prior to template ... String Interpolation: Template literals support string interpolation, where variables or expressions can be included within the string using ${} syntax....
🌐
Theutkarshjaiswal
snippet.theutkarshjaiswal.com › snippets › string-template
How to Interpolate Strings | JavaScript Snippets
January 1, 2024 - Use template literals for string interpolation · javascriptCopy · const name = 'World'; const greeting = `Hello, ${name}!`; console.log(greeting); // "Hello, World!" javascriptCopy · const user = { firstName: 'Alice', age: 30 }; const message = `Welcome ${user.firstName}! You are ${user.age} years old.`; console.log(message);Try it ·
🌐
JavaScript Express
javascript.express › syntax › string_interpolation
String Interpolation
We can use variables within strings — .toString is called automatically to convert each variable to a string.
Find elsewhere
🌐
Sabe
sabe.io › blog › javascript-string-interpolation
How to do String Interpolation in JavaScript | Sabe
August 10, 2022 - The most basic form of string interpolation is to use the concatenation operator + to combine strings. JAVASCRIPTconst name = "John"; const greeting = "Hello " + name; console.log(greeting);
🌐
Esdiscuss
esdiscuss.org › topic › how-to-delay-interpolation-of-template-strings
how to delay interpolation of template strings?
2014 à 09:27, Niloy Mondal <niloy.mondal84 at gmail.com> a écrit : > > I want to define a template string using backquotes in a different file > and then have it interpolated with actual values in a different file. How > can I do it? > > > Just enclose it in a function: > > ```javascript > function foo(a) { > return `some template ${a}` > } > > foo("bar") // will evaluate `some template ${"bar"}` > ``` > > —Claude > -------------- next part -------------- An HTML attachment was scrubbed...
🌐
DigitalOcean
digitalocean.com › community › tutorials › understanding-template-literals-in-javascript
Understanding Template Literals in JavaScript | DigitalOcean
August 27, 2021 - Template literals make a lot of common string tasks simpler by interpolating expressions in strings and creating multi-line strings without any concatenation or escaping. Template tags are also a useful advanced feature of template literals that many popular libraries have used, such as GraphQL and styled-components. To learn more about strings in JavaScript, read How To Work with Strings in JavaScript and How To Index, Split, and Manipulate Strings in JavaScript.
🌐
W3Schools
w3schools.com › js › js_string_templates.asp
JavaScript Template Strings
Template strings provide an easy way to interpolate variables in strings. ... let header = "Template Strings"; let tags = ["template strings", "javascript", "es6"]; let html = `<h2>${header}</h2><ul>`; for (const x of tags) { html += `<li>${x}</li>`; } html += `</ul>`;
🌐
Medium
medium.com › predict › switching-to-es6-part-2-string-interpolation-and-template-literals-2f1b0ee56740
Switching to ES6 (Part 2: String Interpolation and Template Literals) | by Sunny Beatteay | Predict | Medium
November 5, 2018 - First, you need to surround the string you want to interpolate with backticks, which you can find at the top left of your keyboard under the esc key (American keyboards). ... Second, you need to surround the JavaScript code that you want ...
🌐
p5.js
p5js.org › reference
Reference
Calculates coordinates along a Bézier curve using interpolation.
🌐
Squash
squash.io › javascript-template-literals-a-string-interpolation-guide
Javascript Template Literals: A String Interpolation Guide
July 15, 2023 - In this example, the highlight function receives the string parts and interpolated values as arguments. It concatenates the string parts and wraps the interpolated values with <strong> tags. Template literals provide a concise and powerful way to manipulate strings in JavaScript.
🌐
Stanley Ulili
stanleyulili.com › javascript › template-literals-in-javascript-explained-like-your-twelve
Template Literals in JavaScript: Explained like You're Twelve
October 29, 2019 - String interpolation is a process where you can pass a valid JavaScript expression such as a variable into a template literal.
🌐
Dart
dart.dev › language
Introduction to Dart
December 16, 2025 - Here's an example of a class with three properties, two constructors, and a method. One of the properties can't be set directly, so it's defined using a getter method (instead of a variable). The method uses string interpolation to print variables' string equivalents inside of string literals.
🌐
Hacker News
news.ycombinator.com › item
Bash syntax is anything *but* simple or logical. Just look at the insane if-stat... | Hacker News
2 weeks ago - Bash syntax is the pinnacle of Chesterton's Fence. If you can't articulate why it was done that way, you have no right to remove it. Python would be an absolutely unusable shell language · if $command; then <thing> else <thing> fi
🌐
Compiletab
compiletab.com › posts › template literals - string interpolation in javascript (es 6) with examples
Template literals - String interpolation in Javascript (ES 6) with examples | CompileTab
July 13, 2022 - To use the template literals, we wrap the text in backtick (`) instead of the single or double-quotes. The backtick allows us to interpolate variables and expressions using the ${expression} symbol. For example, ... Template literals make it easy to create multi-line strings.
🌐
Ben Ilegbodu
benmvp.com › blog › nested-string-interpolation-in-javascript
Nested string interpolation in JavaScript | Ben Ilegbodu
April 26, 2020 - And it turns out that that Just Works™. I was afraid that the second backtick to start the nested interpolation would be parsed as the closing backtick from the beginning, but apparently once you're inside of a ${ } expression another set of backticks can be used! To be honest, it's a bit gnarly to read. I should probably break it up into two expressions like: const locationSuffix = venue ? ` (${venue})` : '' const fullLocation = `${location}${locationSuffix}` But it's still pretty cool to know that I've got nested string interpolation in my tool bag.