Tagged template literals

22/08/20181 Min Read — In JavaScript, ES6

ES6 TIP: Often forgotten Use tagged template literals to run a template string through a function.

function boldMe(strs, ...vals) {
  let str = strs.map((string, i) => `${string}${vals[i] ? `<b>${vals[i]}</b>` : ''}`);
  return str.join('');
}

const make = 'Porsche';
const model = '718 Cayman';
const sentence = boldMe`My next car is a  ${make} ${model}`;

console.log(sentence);