JavaScript Template Literals

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any JavaScript Question?