Template literals tag function apdorojimas

    0

    0

    bazinis-naudojimastemplate-literalstagged-templates

    https://dev.to/sarah_chima/tagged-template-literals-2ho

    function highlight(strings, ...rest) {
      let str = "";
    
      strings.forEach((string, i) => {
        if (rest[i] != undefined){
          str += `${string} <b>${rest[i]}</b>`;
        } else {
          str += `${string}`;
        }
      });
    
      return str;
    }
    
    const name = "Kelvin";
    const food = "Rice";
    const sentence = highlight`My name is ${name} and I love eating ${food}, cool right?`;
    
    document.body.innerHTML = sentence;
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.