liveBook · Manning

Interpolation

As explained in Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

The insertion of a value into a string’s text during string construction so the value becomes part of the resulting string.

String interpolation inserts a dynamic value while creating a string. In JavaScript, template literals use backticks and `${...}` to place values or expressions inside the string. section 7.1

A cart message

`You have ${cart.length} items in your cart` inserts the cart length into the message; concatenation can produce the same string but requires joining separate pieces.

A couple of useful distinctions:

  • A template literal interpolates its values when created; wrap it in a function to generate strings again with different values. section 7.2

How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it

How deep it goes
Shows `${...}` expressions and contrasts interpolation with concatenation, without detailing evaluation internals.
Examples
Uses cart counts, greetings, mad libs, prices, and product HTML.
What you can do after
Build it from scratch: construct strings with dynamic values using template literals instead of concatenation.
How it connects
Connects interpolation to template literals and string concatenation.

Also explained in

Compare how 4 books explain interpolation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.