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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Strings
Handling text — strings in JavaScript - Learn web development | MDN
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 will be included in the string:
🌐
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.
🌐
W3Schools
w3schools.com › js › js_variables.asp
JavaScript Variables
If you put a number in quotes, it will be treated as a text string. const pi = 3.14; let person = "John Doe"; let answer = 'Yes I am!'; Try it Yourself » · You can declare many variables in one statement. Start the statement with let or constand separate the variables by comma: let person = "John Doe", carName = "Volvo", price = 200; Try it Yourself » ... In JavaScript, the equal sign (=) is an assignment operator, not an equal to operator.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript - Declare String Variables - JavaScript - The freeCodeCamp Forum
September 11, 2023 - Your code so far var darko = myFirstName ; var rudnik = myLastName ; Your browser information: User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15 Challenge: Basic JavaScript - Declare String Variables Link to the ...
🌐
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 - In the past, developers used functions like sprintf() from libraries, but these are largely obsolete due to the simplicity of template literals. Template literals (backticks and ${} syntax) are recommended for creating strings with variables because they are more readable, support multi-line strings, and make it easy to include expressions and complex formatting.
🌐
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 - Unlike regular strings, we can ... pull values into our string. If we use ${ and } to enclose the name of a variable, and that variable's value will be spliced into our string....
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › what-is-a-string-in-javascript
What is a String in JS? The JavaScript String Variable Explained
November 7, 2024 - This means that the original string "John Doe" still exists in memory, but the variable name now refers to the new string "Jane Doe". Strings in JavaScript can be transformed and processed in various ways, such as converting them to uppercase or lowercase, extracting substrings, searching for specific characters or sequences, and comparing strings to determine whether they are equal.
🌐
TutorialsPoint
tutorialspoint.com › How-to-declare-String-Variables-in-JavaScript
How to declare String Variables in JavaScript?
var str = "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>
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Variables
To create a variable in JavaScript, use the let keyword. The statement below creates (in other words: declares) a variable with the name “message”: ... The string is now saved into the memory area associated with the variable.
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript string variable | basics
JavaScript string variable | Basics
January 18, 2024 - JavaScript string Variables in JavaScript are named containers that store a text value. For a variable to be a string type, the value assign
🌐
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.
🌐
GitHub
github.com › EQuimper › CodeChallenge › blob › master › javascript › FreeCodeCamps › Basic JavaScript › Declare String Variables.md
CodeChallenge/javascript/FreeCodeCamps/Basic JavaScript/Declare String Variables.md at master · EQuimper/CodeChallenge
It is a string because it is a series of zero or more characters enclosed in single or double quotes. Create two new string variables: myFirstName and myLastName and assign them the values of your first and last name, respectively.
Author   EQuimper
🌐
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.
🌐
Medium
medium.com › @amarkanala › get-variable-name-as-a-string-in-javascript-cc8c5443df4a
Get “variable” name as a string in JavaScript | by Amar Kanala | Medium
September 13, 2020 - Get “variable” name as a string in JavaScript There might be a usecase to get variable name as a string, perhaps for logging purposes. We can do this by constructing object using shorthand and …
🌐
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.