Template Literals

Template Literals
πŸ‘¨β€πŸ’Ό Remember how tedious string concatenation was? Template literals make combining strings and expressions much easier!
Instead of quotes, template literals use backticks:
console.log(`Hello, World!`)
What makes these so special is you don't have to escape quotes or even newline characters:
console.log(`Hello,
World!`)

// Prints the same thing as: console.log('Hello,\nWorld!')
In addition, while you can still use string concatenation, you can embed any expression using ${expression}:
console.log(`2 + 2 = ${2 + 2}`) // Prints: 2 + 2 = 4
console.log(`Hello, ${'World'}!`) // Prints: Hello, World!
🐨 Open
index.ts
and complete the following tasks:
  1. Log a template literal whose output is exactly The answer is 42, embedding a calculation that evaluates to 42 (do not hardcode the digits 42 as plain text alone)
  2. Log a greeting template literal that includes both Hello and TypeScript (for example: Hello, TypeScript!)
  3. Log a math sentence whose output includes 50 as the computed answer (for example: 10 times 5 equals 50), embedding the multiplication in the template

Completion criteria

Your output should include:
  • The answer is 42
  • Text containing both Hello and TypeScript (any casing is fine for the check)
  • The number 50 as part of a logged math sentence
πŸ’° The backtick key is usually in the top-left of your keyboard, below Escape.

Please set the playground first

Loading "Template Literals"
Loading "Template Literals"