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

157
Visualizações
Is it possible to insert a variable into a string after the string has been created?

I need to mutate a strings quotes from double/single quotes to backticks, after it has already been created, so that I can add variables into the string.

I tried using replace(), but it seems as though JS does not evaluate the variable again after the replace method runs.

I am trying to understand if it is something that is possible to do, or variables can only be added to a string in JavaScript manually, and not dynamically?

Here is my code:

const variable = 9;

let strWithVar = "${variable}".replace(/"+/g, "`");

console.log(strWithVar);

The current return value is:

${abc}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maybe do:

var world = "World";
var hello = `Hello, ${world}`;
console.log(hello)
var bob = "bob"
var helloBob = `${hello}, ${bob}`
console.log(helloBob)

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