Values, Types, and Expressions
Template Literals
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
namestarts asAda.ageis30.greetingbecomesAda is 30.upperbecomesADA.- The program prints
greeting=Ada is 30andupper=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.