Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
JavaScript template literals substitute variable later (before values are known)

Is it possible to use template literals somehow before the values a known. Every demo on JS template literals looks like this:

var name = "John";
var s = `Hello ${name}`;

But in real world, templates are defined before we know variable values. Somewhere is defined template (on page load):

var s = `Hello ${name}`;

And then, 5 minutes later, when user logs in I want to use this template but it was already substituted so how to actually do it? Similar issue would be how to use template multiple times.

I can imagine having it some wrapper function but I want to have templates in JSON where there cannot be functions. Is it even possible?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No.

Template strings are for populating at the time the template string is declared.

If you want to define it early and populate it later, define it inside a function. (An option you've rejected).

You might consider another template engine such as Nunjucks or EJS … but they'll still effectively be wrapped in a function.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda