Build strings by embedding values with backticks.

Template Literals

template_strings.js
const name = "Ada";
const age = 30;
const greeting = `${name} is ${age}`;
const upper = name.toUpperCase();

console.log("greeting=" + greeting);
console.log("upper=" + upper);

Follow the Template

  1. name starts as Ada.
  2. age is 30.
  3. greeting becomes Ada is 30.
  4. upper becomes ADA.
  5. The program prints greeting=Ada is 30 and upper=ADA. | name | greeting | upper | | --- | --- | --- | | Ada | Ada is 30 | ADA | | Bo | Bo is 30 | BO | | Cy | Cy is 30 | CY |
template-strings A template literal uses backticks and `${...}` to embed values directly in a string. String methods like `toUpperCase` return new strings.

Exercise: template_strings.js

Reproduce greeting=Ada is 30 and upper=ADA, then use the pinned names Bo and Cy to predict each output.