# JavaScript printf Equivalent: Use Template Literals

> Format strings with variable values in JavaScript using template literals, backtick strings with ${} expressions, instead of printf or String.Format

**URL:** https://sentry.io/answers/equivalent-of-printf-or-string-format-in-javascript/

---

## The Problem

In JavaScript, how can I print strings containing the values of variables? I would use `printf()` to do this in C or PHP and `string.Format()` to do this in C# or `String.format()` in Java. What is the JavaScript equivalent of these functions?

## The Solution

Modern JavaScript supports [template strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) delimited with backticks, which can contain arbitrary JavaScript expressions inside one or more `${}` blocks. For example:

```javascript
const myNum = 20;
const myString = `The value of myNum is ${myNum}`;
const myString2 = `The value of myNum + 10 is ${myNum + 10}`;

console.log(myString); // will print "The value of myNum is 20"
console.log(myString2); // will print "The value of myNum + 10 is 30"
```

---

*Source: [sentry.io/answers/equivalent-of-printf-or-string-format-in-javascript/](https://sentry.io/answers/equivalent-of-printf-or-string-format-in-javascript/)*
