ES6 in Depth
  • Introduction
  • Installation
  • Block Scope
    • Constant
    • Use cases
  • Template String
    • New String Methods
    • Tagged Template Literal
  • New Number Methods
  • Arrow Function
    • Default Parameters
    • Lexical This Scope
    • Where not to use arrow function
  • Object Enhancement
  • New Array Methods
    • For Of
  • Spread Operator
  • Destructuring
    • Array Destructuring
  • Class
  • Symbols
  • New Data Structures
    • Set
    • Map
    • WeakSet
    • WeakMap
    • Iterators
    • Generators
  • Promise
  • Import Export
Powered by GitBook
On this page

Was this helpful?

  1. Template String

Tagged Template Literal

const name = "Hemant";
const age = 30;


function highlight(strings, ...values){
  let str = '';

  strings.forEach((s, i)=> {
    str += `${s} <span class="hl">${values[i] || ''}</span>`;
  });

  return str;
}

var str = highlight`my name is ${name} my age is ${age}`;
console.log(str)
PreviousNew String MethodsNextNew Number Methods

Last updated 4 years ago

Was this helpful?