ES2015Strings / ES2015

Template strings

You can use ${...} to add expressions inside strings. To do this, surround your string with backticks.

var message = `Hello ${name}`

Template strings are also used for multi-line strings.

var help = `
  $0 [options] [files...]

Why is it called a "template"? Next

Tagged templates

Template strings can be "tagged" by putting a function before it.

tpl `hello ${name}! I'm ${me}`

tpl is a function you write. It will be invoked like so. While this is not used very often, it lets us write things like template engines.

function tpl (strings, values) {
  strings ['hello ', '! I'm', '']
  values  [name, me]
Further reading...

Let's learn about what's new with functions. Next chapter