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
Strings are dealt with similarly to numbers at first glance, but when you dig deeper you'll start to see some notable differences. Let's start by entering some basic lines into the browser developer console to familiarize ourselves. ... Just like we did with numbers, we are declaring a variable, initializing it with a string value, and then returning the value.
Discussions

How to interpolate variables in strings in JavaScript, without concatenation? - Stack Overflow
I know in PHP we can do something like this: $hello = "foo"; $my_string = "I pity the $hello"; Output: "I pity the foo" I was wondering if this same thing is possible in JavaScript as well. Using More on stackoverflow.com
🌐 stackoverflow.com
Possible to get the name of a variable as string?
Variable names are there for the programmer, not the program. You can probably accomplish what you want by treating car as a string: var my_garage : Dictionary = {"car" : "Mercedes", "motorcycle" : "Harley"} More on reddit.com
🌐 r/godot
24
7
December 3, 2022
Basic JavaScript - Declare String Variables
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 ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 11, 2023
dynamic variable names
Use an object to hold your variable keys, allowing you to use bracket notation to set the object key, which accepts variable names: var someObj = {}; var foo = 'bar'; someObj[foo] = 2; More on reddit.com
🌐 r/learnjavascript
15
3
March 5, 2016
🌐
W3Schools
w3schools.com › js › js_variables.asp
JavaScript Variables
If you put a number in quotes, ... 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 ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › check-if-a-variable-is-a-string-using-javascript
Check if a variable is a string using JavaScript - GeeksforGeeks
August 20, 2024 - let boolValue = true; let numValue = 17; let bool, num; if (typeof boolValue == "string") { bool = "is a string"; } else { bool = "is not a string"; } if (typeof numValue == "string") { num = "is a string"; } else { num = "is not a string"; } console.log(bool); console.log(num); ... The instanceof operator in JavaScript is used to check the type of an object at run time. ... Example: This example shows the implementation of above-explained appraoch. ... let variable = new String(); if (variable instanceof String) { console.log("variable is a string."); } else { console.log("variable is not a string."); }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Template_literals
Template literals (Template strings) - JavaScript | MDN
Template literals are sometimes informally called template strings, because they are used most commonly for string interpolation (to create strings by doing substitution of placeholders).
Find elsewhere
🌐
Quora
quora.com › How-do-I-use-string-content-as-variable-name-in-JS
How to use string content as variable name in JS - Quora
Answer (1 of 9): Why would you want to do that?? You can sort of do a similar thing with object keys: [code]const myVar = "hello"; const obj = { [myVar]: "some content" // {hello: "some content"} } [/code]This actually can be useful - your keys can be ids or names of other “things” and you c...
🌐
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 ...
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
In addition to the general types string and number, we can refer to specific strings and numbers in type positions. One way to think about this is to consider how JavaScript comes with different ways to declare a variable. Both var and let allow for changing what is held inside the variable, and const does not.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String
String - JavaScript | MDN
Objects are first converted to a primitive by calling its [Symbol.toPrimitive]() (with "string" as hint), toString(), and valueOf() methods, in that order. The resulting primitive is then converted to a string. There are several ways to achieve nearly the same effect in JavaScript.
🌐
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 › @ondrej-kvasnovsky › javascript-11-string-variables-b32dde1bd21b
JavaScript #11 — String Variables | by Ondrej Kvasnovsky
March 9, 2021 - It is possible to connect two or more text variables. The connecting is done using the + symbol. It might feel weird, but JavaScript uses + for both adding up two numbers together and for connecting two strings as well.
🌐
Sentry
sentry.io › sentry answers › javascript › check if a variable is a string in javascript
Check if a variable is a string in JavaScript | Sentry
We can do this using JavaScript’s typeof operator along with its strict equality operator. We can test this with the following code: ... // Function to test if variable is a string function isString(variable) { return typeof variable === "string"; } // Variables of different types let myBool = false; let myNum = 12; let myArray = [1, 2, 3] let myObject = { a: 1, b: 2, c: 3} let myString = "Hello world!"
🌐
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.
🌐
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.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Data_structures
JavaScript data types and data structures - JavaScript | MDN
Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types: ... let foo = 42; // foo is now a number foo = "bar"; // foo is now a string foo = true; // foo is now a boolean
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Variables
2 weeks ago - 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.
🌐
Freewebdesigntutorials
freewebdesigntutorials.com › javaScriptTutorials › jsStringObject › declaringStrings.php
Declare a String in JavaScript
We can explicitly declare a string using "new String()" to create the string in memory: this is the JavaScript string constructor function. An optional string argument can also be passed to the constructor. // Declare string variable with string constructor var carter1 = new String("I learn JavaScript"); // Declare an empty string var carter2 = new String(); alert( "|"+ carter2 +"|" );