You can take advantage of Template Literals and use this syntax:

`String text ${expression}`

Template literals are enclosed by the back-tick (` `) (grave accent) instead of double or single quotes.

This feature has been introduced in ES2015 (ES6).

Example

var a = 5;
var b = 10;
console.log(`Fifteen is ${a + b}.`);
// "Fifteen is 15.

How neat is that?

Bonus:

It also allows for multi-line strings in javascript without escaping, which is great for templates:

return `
    <div class="${foo}">
         ...
    </div>
`;

Browser support:

As this syntax is not supported by older browsers (mostly Internet Explorer), you may want to use Babel/Webpack to transpile your code into ES5 to ensure it will run everywhere.


Side note:

Starting from IE8+ you can use basic string formatting inside console.log:

console.log('%s is %d.', 'Fifteen', 15);
// Fifteen is 15.
Answer from bformet on Stack Overflow
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 8931-creating-a-string-with-variables-in-javascript
[JavaScript] - Creating a String With Variables in | SheCodes
Learn how to add a variable to a string using either string concatenation or string interpolation with template literals for a more modern approach.
Discussions

How to insert variables in JavaScript strings? - Stack Overflow
What's the best way to do insert variables in a string in JavaScript? I'm guessing it's not this: var coordinates = "x: " + x + ", y: " + y; In Java, Strings are immutable and doing something like... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How can you insert a variable into a string?
๐ŸŒ forum.jquery.com
How do I put a variable in a string using javascript - Stack Overflow
How do I put a variable in a string in JavaScript? Example: $('#contactForm').animate({"marginLeft": "+=680px"}, "slow"); I would like to use in a variable instead of 680px, is there a way to do ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
I am having trouble adding variables into a string. I am using ${variable} but it never does anything.
Get access to thousands of hours ... in the community today. Start your free trial ... is this how you add variables and parameters into strings? i did it just like in the video but it did not print out the actual parameters. Full Stack JavaScript v1 Techdegree Graduate ... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
2
March 22, 2017
๐ŸŒ
DEV Community
dev.to โ€บ sprite421 โ€บ adding-variables-into-strings-using-javascript-s-template-literals-16m2
Adding Variables into Strings using JavaScript's Template Literals - DEV Community
December 20, 2020 - Instead of enclosing our string in quotes as usual, we'll use backticks `, aka grave accents or acutes. They look similar to single quotes, but they turn our string into a template literal.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ javascript โ€บ javascript variable in string
How to Insert Variable Into String in JavaScript | Delft Stack
February 2, 2024 - For instance, for displaying a numeric value, the placeholder in the sentence should be %d for string data type it is %s. let op1 = 5, op2 = 10, operation = 'Sum'; console.log('%s of %d and %d is %d.', operation, op1, op2, (op1 + op2)); ... Sum of 5 and 10 is 15. If we forget to consider the type of parameter passed, there is a type mismatch. JavaScript will try to typecast the variable, and it will add the resultant value to the string.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-create-a-string-with-variables-in-javascript
How to Create a String with Variables in JavaScript? - GeeksforGeeks
November 12, 2024 - To create a string with variables in JavaScript, you can use several methods, including string concatenation, template literals, and the String methods.
Find elsewhere
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn โ€บ JavaScript โ€บ First_steps โ€บ Strings
Handling text โ€” strings in JavaScript - Learn web development | MDN
July 27, 2024 - Template literals mostly behave the same as normal strings, but they have some special properties: You can embed JavaScript in them. You can declare template literals over multiple lines. Inside a template literal, you can wrap JavaScript variables or expressions inside ${ }, and the result ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Use Variables in Strings in Javascript - YouTube
To use variable text in a string in Javascript, define the variable text as a variable.Combining static text with a variable is done using the plus sign. The...
Published ย  April 20, 2023
๐ŸŒ
Linux Hint
linuxhint.com โ€บ insertion-of-variable-into-string-using-javascript
Insertion of Variable into String Using JavaScript
September 11, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
๐ŸŒ
YouTube
youtube.com โ€บ thenewboston
Beginner JavaScript Tutorial - 5 - Using Variables with Strings - YouTube
Source Code: https://github.com/thenewboston-developersCore Deployment Guide (AWS): https://docs.google.com/document/d/16NDHWtmwmsnrACytRXp2T9Jg7R5FgzRmkYoDt...
Published ย  March 16, 2011
Views ย  496K
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-declare-string-variables-in-javascript
How to declare String Variables in JavaScript?
September 14, 2023 - var sentence = "In elementary school we learn "basic skills" like reading and writing"; ... <html> <head> <title>JavaScript Strings</title> </head> <body> <script> var str1 = 'It is 5 o'clock in the morning.'; var str2 = "In elementary school, we learn "basic skills" like reading and writing"; document.write(str1 + "</br>" ); document.write(str2 + "</br>"); </script> </body> </html>
๐ŸŒ
Pluralsight
pluralsight.com โ€บ tech insights & how-to guides โ€บ software development
How to work with strings in JavaScript | Pluralsight
May 19, 2025 - Declaring a string in JavaScript means defining a variable that will hold a string value. To declare a string variable in JavaScript, you use one of the following keywords: var, let, or const.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_variables.asp
JavaScript Variables
The let and const keywords were new to JavaScript in 2015. var x = 5; var y = 6; var z = x + y; Try it Yourself ยป ... JavaScript variables can hold 8 datatypes, but for now, just think of numbers and strings. Strings are text written inside quotes. Numbers are written without quotes. If you put a number in quotes, it will be treated as a text string.
๐ŸŒ
KIRUPA
kirupa.com โ€บ javascript โ€บ combining_strings_variables.htm
Combining Strings and Variables
Learn how to combine strings made up of static text and variable values using both the concatenation and template literal approaches.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-work-with-strings-in-javascript
How To Work with Strings in JavaScript | DigitalOcean
August 24, 2021 - In this article, we went over the basics of working with strings in JavaScript, from creating and displaying string literals using single and double quotes, creating template literals, concatenation, escaping, and assigning string values to variables.
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 516db5a1ac9fa9882c001583
An efficient way to add a variable $var into a string | Codecademy
The syntax โ€œStringStuff {$var} MoreStringStuffโ€ is an efficient way to add a variable $var into a string.