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.
The Well-Grounded Rubyist, Fourth EditionString interpolation is the Ruby language feature that evaluates embedded expressions and inserts their results into a string or regular expression.
Tiny CSS ProjectsSass interpolation evaluates an expression and inserts its result into generated CSS text, such as selectors, property names, or values.
to_sused by · to_s is a Ruby conversion method that returns a string representation of its receiver.
template literalused by · A JavaScript string literal delimited by backticks that supports multiline text and embedded expressions.
f-stringimplemented by · An f-string is a Python formatted string literal that evaluates embedded expressions and inserts their formatted values into the resulting string.
single-quoted stringcontrasts with · A single-quoted string is a string literal delimited by single quotation marks, with language-defined rules for escapes and interpolation.
regular expressionuses · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
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.