Template Literals

Download javascript eBook

Introduction

Template literals are a type of string literal that allows values to be interpolated, and optionally the interpolation and construction behaviour to be controlled using a "tag" function.

Syntax

  • message = `Welcome, ${user.name}!`
  • pattern = new RegExp(String.raw`Welcome, (\w+)!`);
  • query = SQL`INSERT INTO User (name) VALUES (${name})`

Remarks

Template Literals were first specified by ECMAScript 6 §12.2.9.

Related Examples

Stats

316 Contributors: 9
Sunday, May 7, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook