JSFiddle - React, Tailwind, and code Playground

by Deepak Anand

JavaScript

function interpolate(literals, ...substitutions) {
debugger
    let interpolation = '';

    // loop through based on length of substitutions
    // since its shorter by 1
    for (let i = 0; i < substitutions.length; i++) {
        interpolation += literals[i] + substitutions[i];
    }

    // add the extra literal to the end
    interpolation += literals[literals.length - 1];

    return interpolation;
}

let firstName = 'Ben',
	lastName = "Ilegbodu";

// output: Name: Ilegbodu, Ben
console.log(interpolate`Name: ${lastName}, ${firstName}`);